我需要以编程方式取消选中复选框,但检查列表在对话框中。这会改变解决方案吗?到目前为止我所拥有的:
CharSequence[] items = itemList.toArray(new CharSequence[itemList.size()]);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Select categories");
builder.setMultiChoiceItems(items, null,
new DialogInterface.OnMultiChoiceClickListener() {
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
if (isChecked){
if(chosenCat.size() < 10){
chosenCat.add(items[which].toString());
}else{
Toast.makeText(getApplicationContext(), "Max 10 categories to compare.", Toast.LENGTH_SHORT).show();
//uncheck
items.isChecked = false; // --> wrong
chosenCat.remove(items[which].toString());
}
}else{
chosenCat.remove(items[which].toString());
}
}
});