【问题标题】:What is the process of creating an AlertDialog with ListView in Android?Android中使用ListView创建AlertDialog的流程是什么?
【发布时间】:2010-09-08 10:04:22
【问题描述】:

我想知道创建 AlertDialog 的过程或顺序。我问这个问题的顺序是我想过滤和禁用 AlertDialog 中的某些列表项。这必须是动态的。所以我选择覆盖 onPrepareDialog(int id, Dialog dialog) 方法。

首先我在 onCreateDialog(int id) 方法中创建一个 AlertDialog

protected Dialog onCreateDialog(int id) {
    --------

    builder.setMultiChoiceItems(itemsId, checkedItems, mListenter);

    ---------
}


protected void onPrepareDialog(int id, Dialog dialog) {
    -----------
    ListView mListView = ((AlertDialog)dialog).getListView();
    mListView.setItemChecked(0, false);
    mListView.invalidateViews();

    View view = mListView.getChildAt(0);
    -----------
}

但是这些代码不起作用。第一项在我之前检查后仍然被检查。 并且第一次显示对话框时 ChildView 为空,为什么? 如何在 ListView 中归档某些项目以及如何禁用但显示某些项目。

【问题讨论】:

    标签: android listview android-alertdialog


    【解决方案1】:

    检查我在How to update array of items in an AlertDialog list built with AlertDialog.builder after creation 上的回答是否符合要求。至少对我有用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-11
      相关资源
      最近更新 更多