我有一個顯示覆選框列表的對話框。每次打開時應檢查哪些框來自編輯文本。我搜索了一種不允許緩存對話框的方法,但無法找到如何做到這一點。現在我重寫onPrepareDialog以在對話框打開前設置複選框。我刪除了我的edittext的內容,打開對話框,仍然檢查了相同的框...任何人都可以告訴我如何重置複選框?無法在onPrepareDialog中設置複選框狀態
@Override
protected void onPrepareDialog(int id, Dialog dialog) {
ListView lv = ((AlertDialog) dialog).getListView();
if (lv == null)
return;
boolean[] checked = cbDialog.setAndGetCheckedArray();
String s = "onPrepareDialog... checked=";
for (int i=0; i<checked.length; i++)
s+="["+i+"="+checked[i]+"]";
System.out.println(s);
// if edittext is empty, all entries in checked[] are false here,
// but these changes do NOT affect the checkboxes in the dialog:
for (int i=0; i<checked.length; i++)
if (checked[i])
lv.setItemChecked(i, true);
else
lv.setItemChecked(i, false);
}