here is my code which i use for multiple selection.
String[] items = new String[education_list.size()];
items = education_list.toArray(items);
//final CharSequence[] items = (CharSequence[]) education_list.toArray();
final ArrayList seletedItems=new ArrayList();
AlertDialog.Builder builder = new AlertDialog.Builder(Activity_EditProfile.this);
builder.setTitle("Select Education");
builder.setMultiChoiceItems(items, null,
new DialogInterface.OnMultiChoiceClickListener() {
// indexSelected contains the index of item (of which checkbox checked)
@Override
public void onClick(DialogInterface dialog, int indexSelected,
boolean isChecked) {
if (isChecked) {
// If the user checked the item, add it to the selected items
// write your code when user checked the checkbox
seletedItems.add(indexSelected);
} else if (seletedItems.contains(indexSelected)) {
// Else, if the item is already in the array, remove it
// write your code when user Uchecked the checkbox
seletedItems.remove(Integer.valueOf(indexSelected));
}
}
})
// Set the action buttons
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
// Your code when user clicked on OK
// You can write the code to save the selected item here
System.out.println(seletedItems.toString());
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
// Your code when user clicked on Cancel
}
});
dialog = builder.create();//AlertDialog dialog; create like this outside onClick
dialog.show();
}
Now my education list fills dynamically as per response from webservice. The selectedItem arraylist get filled with indexes. I want checked items names. How can i achieve this??
Aucun commentaire:
Enregistrer un commentaire