gpt4 book ai didi

android - alertdialog ListView 取消选中

转载 作者:行者123 更新时间:2023-11-30 04:25:02 25 4
gpt4 key购买 nike

我用 ListView 创建 AlertDialog,并且适配器以编程方式具有元素 CheckAll/UncheckAll 元素。这行得通。但是当我通过触摸屏检查项目时,然后按下 checkall,然后取消选中,选中的元素保持选中状态。

    DialogInterface.OnMultiChoiceClickListener coloursDialogListener = new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which,
boolean isChecked) {

ListView list = ((AlertDialog) dialog).getListView();
long[] a = list.getCheckItemIds();
if (which == 0) {
if (isChecked) {
for (int i = 0; i < list.getCount(); ++i)
list.setItemChecked(i, true);
} else {
for(int i=0;i<list.getCount();++i)
list.setItemChecked(i, false);
}
a = list.getCheckItemIds();//fucntion return empty array
//but on screen checked element is Check.
return;
}
}
};

更新:我发现错误发生的时间。如果在函数中

setMultiChoiceItems(CharSequence[] items, boolean[] checkedItems, DialogInterface.OnMultiChoiceClickListener 监听器)

我设置参数 checkedItems 出现错误。如果我将 checkedItems 参数设置为空,则不会发生错误。有什么想法吗?

更新:我在 bugtracker google 上打开这个问题,更多数据请看 here

最佳答案

getCheckItemIds() 方法此方法已弃用。请改用 getCheckedItemIds()。

http://developer.android.com/reference/android/widget/ListView.html

关于android - alertdialog ListView 取消选中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8659858/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com