当我重新打开对话框以显示被选中的项目时,它们显示正常,但如果我选择另一个项目,则之前选择的其他项目将被删除,并且只有新项目显示在arraylist中。我想在arraylist中显示新选择的项目以及之前选择的项目。
AlertDialog.Builder builder = new AlertDialog.Builder(Setting.this);
builder.setTitle("Choose Categories to hide");
int L = MyGlobals.categories2.length;
boolean[] checkedItems = new boolean[L];
for (int i = 0; i < L; i++) {
try {
if(categoryExist(MyGlobals.categories2[i])){
checkedItems[i] = true;
}else {
checkedItems[i] = false;
}
}catch(Exception e) {
e.printStackTrace();
}
}
builder.setMultiChoiceItems(MyGlobals.categories2, checkedItems, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
if (isChecked) {
selected_categories.add(MyGlobals.categories2[which]);
} else if(selected_categories.contains(which)) {
selected_categories.remove(MyGlobals.categories2[which]);
}
}
});