如何刷新对话框数据?Android showDialog()-具有复选框bool[]首次打开后不会更新

如何刷新对话框数据?Android showDialog()-具有复选框bool[]首次打开后不会更新,android,android-intent,android-alertdialog,Android,Android Intent,Android Alertdialog,我有一个对话框,它有一个字符串数组(名称)和布尔值数组(选中与否) 在对话框选择外部,我更新布尔值,第一次单击它们会更新,之后它们不再同步 OnCreateDialog只调用一次。我试图通过调用(d.dissmiss())来取消对话框,但无法使其同步 有人能帮忙吗 protected String[] _Geooptions; protected boolean[] _Geoselections; Dialog d; @Override protected Dialog onCrea

我有一个对话框,它有一个字符串数组(名称)和布尔值数组(选中与否)

在对话框选择外部,我更新布尔值,第一次单击它们会更新,之后它们不再同步

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;
        }
    }
}
如何刷新对话框数据

您正在更新数组的数据,但没有告诉内部
ListView
,该视图由
AlertDialog
用于
setMultiChoiceItems()
方法。更新布尔数组时,获取对
AlertDialog
列表视图的引用,获取其适配器并在其上调用
notifyDataSetChanged

// after updating the array
((BaseAdapter) ((AlertDialog) d).getListView().getAdapter()).notifyDataSetChanged();

这个答案来源于Luksprog关于访问对话框列表视图的评论

我将Dialog d变量更改为AlertDialog,然后在我的clearALL或SelectAll按钮调用中,我手动迭代列表并更新选项-这不是最有效的方法,但似乎是唯一有效的方法(他的notifyonchange对我没有任何帮助-我不明白为什么它不会…)

ListView卷曲列表=d.getListView();
对于(int i=0;i
hmm。。。不起作用-但你确实帮我弄明白了我可以获取listview,然后手动执行setItemChecked我认为你写的东西正是我要找的,但无法弄清楚notify存储在哪里。。。我觉得很奇怪,这对我来说不起作用(我在点击按钮后打开了对话框,没有任何更改)@morty346我的代码应该可以工作,因为我已经用过很多次了。也许这与你改变价值观的方式有关(你在问题中没有解释)。我也这么认为。。。这些值只是在按钮事件OnClickListener OnClickLis=new OnClickListener(){@Override public void onClick(View v){mapGeoManager.SelectFilters(false);((BaseAdapter)((AlertDialog)d.getListView().getAdapter()).notifyDataSetChanged();}}public void SelectFilters(布尔选择){for(int i=0;i<_Geoselections.length;++i){_Geoselections[i]=selection;}FilterUpdate();}
ListView curList = d.getListView();
for(int i = 0; i < mapGeoManager._Geoselections.length; ++i)
    curList.setItemChecked(i, mapGeoManager._Geoselections[i]);