我在对话框中使用选中的ListView
。我可以将所有已检查的项目存储起来,如下所示:
builder.setMultiChoiceItems(arr, null,
new DialogInterface.OnMultiChoiceClickListener() {
// indexSelected contains the index of item (of which checkbox checked)
@Override
public void onClick(DialogInterface dialog, int indexSelected,
boolean isChecked) {
if (isChecked) {
brandNameIDMap.put(brandList.getItem(indexSelected).getProductID(), brandList.getItem(indexSelected).getProductName());
//Log.i("ID", "onClick: "+brandList.getItem(indexSelected).getProductID());
//seletedItems.add(indexSelected);
} else{
brandNameIDMap.remove(brandList.getItem(indexSelected).getProductID());
}
}
});
问题:
现在我想重新打开Dialog
,并且需要自动选择之前选择的项目。我怎么能这样做?
答案 0 :(得分:0)
创建一个数组
Boolean checked[] = new Boolean[arr.size()];
然后检查任何项目,将其添加到数组中。
builder.setMultiChoiceItems(arr, checked,
new DialogInterface.OnMultiChoiceClickListener() {
// indexSelected contains the index of item (of which checkbox checked)
@Override
public void onClick(DialogInterface dialog, int indexSelected,
boolean isChecked) {
if (isChecked) {
checked[indexSelected]=true;
brandNameIDMap.put(brandList.getItem(indexSelected).getProductID(), brandList.getItem(indexSelected).getProductName());
//Log.i("ID", "onClick: "+brandList.getItem(indexSelected).getProductID());
//seletedItems.add(indexSelected);
} else{
checked[indexSelected]=false;
brandNameIDMap.remove(brandList.getItem(indexSelected).getProductID());
}
}
});