我有一个Dialog,其中包含一系列字符串(名称)和bools(已检查或未选中)
对话框选择外部我更新bools,第一次点击它们会更新,之后它们不再同步
OnCreateDialog只调用一次。我尝试通过调用(d.dissmiss())来解除对话,但我无法让它同步。
任何人可以提供帮助吗?
protected String[] _Geooptions;
protected boolean[] _Geoselections;
Dialog d;
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case 0:
d = new AlertDialog.Builder(this)
.setTitle("Set Geo Filters")
.setMultiChoiceItems(mapGeoManager._Geooptions,
mapGeoManager._Geoselections,
new GeoDialogSelectionClickHandler())
.setPositiveButton("OK", new GeoDialogButtonClickHandler())
.create();
return d;}
public class GeoDialogSelectionClickHandler implements
DialogInterface.OnMultiChoiceClickListener {
public void onClick(DialogInterface dialog, int clicked,
boolean selected) {
Log.i("ME", mapGeoManager._Geooptions[clicked] + " selected: "
+ selected);
mapGeoManager.FilterUpdate();
}
}
public class GeoDialogButtonClickHandler implements
DialogInterface.OnClickListener {
public void onClick(DialogInterface dialog, int clicked) {
switch (clicked) {
case DialogInterface.BUTTON_POSITIVE:
Log.d(TAG, "ON CLICK BUTTON POSITIVE!");
mapGeoManager.FilterUpdate();
break;
}
}
}
答案 0 :(得分:1)
如何刷新对话框数据?
您正在更新数组的数据,但您没有告诉ListView
AlertDialog
方法使用的内部setMultiChoiceItems()
。当您更新布尔数组时,获取对AlertDialog
的{{1}}的引用,获取其适配器并在其上调用ListView
:
notifyDataSetChanged
答案 1 :(得分:0)
本答案源于Luksprog对“对话框列表视图”的评论
我将Dialog d变量更改为AlertDialog,然后在我的clearALL或SelectAll按钮上调用I然后手动遍历列表并更新选项 - 这不是最有效的方法,但它似乎工作的唯一方式(他的notifyonchange没有为我做任何事 - 我很困惑,为什么它不会......)
ListView curList = d.getListView();
for(int i = 0; i < mapGeoManager._Geoselections.length; ++i)
curList.setItemChecked(i, mapGeoManager._Geoselections[i]);