我有一个 alertDialog 提示用户进行多项选择,我可以进行少量选择并将所选项目保存在 arrayList 中,但是当我再次触发该 alertBox 时,它会被重置并且所有复选框都未选中,我希望它们保留状态我将它们留在原处,直到我手动重置它们。这是如何运作的?我的代码:
ArrayList<String> participants = db.getNames();
final String[] arr = participants.toArray(new String[participants
.size()]);
boolean[] checkedItems = new boolean[participants.size()];
final ArrayList<String> selectedParticipants = new ArrayList<String>();
AlertDialog.Builder b = new AlertDialog.Builder(this);
b.setTitle("Select the participants:");
b.setMultiChoiceItems(arr, checkedItems,
new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which,
boolean isChecked) {
if (isChecked) {
selectedParticipants.add(arr[which].toString());
}
}
});
b.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Toast.makeText(EnterExpense.this,
"" + selectedParticipants, Toast.LENGTH_SHORT)
.show();
}
}).setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});