How Do I Obtain The Setmultichoiceitems Items From My Alertdialog?
Solution 1:
use getListView() of AlertDialog class. and fetch the listView. i.e when you call .create() at the end this will fetch you a new AlertDialog.
Then use one of the following methods:
1. getCheckItemPositions:SparseBooleanArray
2. getCheckedItemIds:long[]
I can provide you with demo code. Give me 10-15 mins.
Solution 2:
Pass a reference to byte[]
in setMultiChoiceItems()
.
finalboolean[] booleans = {false, true, false, true, false, false, false};
Then check the value of booleans
inside setPositiveButton()
.
If you need to pass this AlertDialog
around, then extend AlertDialog
and have create a field boolean
as described in 1.
Solution 3:
To get checked items when setMultiChoiceItems is used in AlertDialog.Builder, you must create DialogInterface.OnMultiChoiceClickListener with even empty onClick. Only on this condition checkedItems in second params will be used and updated internally in AlertController and reflect checked items on exit (i.e. in setPositiveButton callback)
Check this AlertController code:
...
} elseif (mOnCheckboxClickListener != null) {
listView.setOnItemClickListener(new OnItemClickListener() {
publicvoidonItemClick(AdapterView parent, View v, int position, long id) {
if (mCheckedItems != null) {
mCheckedItems[position] = listView.isItemChecked(position);
}
mOnCheckboxClickListener.onClick(
dialog.mDialogInterface, position, listView.isItemChecked(position));
}
});
}
...
Post a Comment for "How Do I Obtain The Setmultichoiceitems Items From My Alertdialog?"