Jose Jose - 10 days ago 6
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,
android.R.layout.simple_list_item_1,
new String[] { "" }, new int[] { android.R.id.text1 });

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?
multiSelectionSpinner.setItems(array);
}

Answer

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();
    itemList.add(item);
}
String[] itemArr = new String[itemList.size()];
itemArr = itemList.toArray(itemArr);
multiSelectionSpinner.setItems(itemArr);