当我重新打开对话框以显示被选中的项目时,它们显示得很好,但是如果我选择另一个项目,那么之前选择的其他项目将被删除,只有新的项目显示在 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]);
}
}
});