Jose Jose - 1 year ago 80
Android Question

How can I put items in an array in differente checkboxes?

I have an array that populates my application checkboxes, but instead of creating multiple checkboxes it puts all the array in just one. I want to split the elements in the array in the diferent checkboxes.

Image of whats going on

SimpleAdapter simpleAdapter = new SimpleAdapter(getApplicationContext(), employeeList,
new String[] { "" }, new int[] { });

for(int i=0; i<simpleAdapter.getCount();i++ ){
teste = teste + simpleAdapter.getItem(i).toString() +"\n";
String[] array = {teste.replace("{","").replace("}","").replace("=","").trim()}; //tira os espa├žos vazios?

Answer Source

You are just resetting the spinner with an array containing a single item. You need to add the elements to the array in each run of the loop :

ArrayList<String> itemList = new ArrayList<String>();

for(int i=0; i<simpleAdapter.getCount();i++ ){
    String item = simpleAdapter.getItem(i).toString();
    item = item.replace("{","").replace("}","").replace("=","").trim();
String[] itemArr = new String[itemList.size()];
itemArr = itemList.toArray(itemArr);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download