gpt4 book ai didi

android - 如何处理listview android中的复选框?

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

我在 ListView 中使用复选框。代码工作正常。我击中了所有列表检查项目。我使用下面的代码来获取选中的项目。但它给出了列表重点区域的结果。

int firstPosition = list.getFirstVisiblePosition();

for(int i = firstPosition; i < list.getCount(); i++){
View v = list.getChildAt(i);
if(v != null){
cbx = (CheckBox)v.findViewById(R.id.c_checkbox);
if(cbx.isChecked()){
//adding this check box to one sub list
}
}
}

但它只给出可聚焦的列表项结果。根据子列表,我想填充我的菜单,这就是为什么我在 onPrepareOptionsMen() 方法中使用此代码并单击菜单项从数据库中删除此列表。我找到了另一个解决方案是

long checkedPos[] =list.getCheckedItemIds();

但它是给予

01-31 12:07:16.042: WARN/dalvikvm(294): VFY: unable to resolve virtual method 808: Landroid/widget/ListView;.getCheckedItemIds ()[J 01-31 12:07:16.042: WARN/dalvikvm(294): VFY: rejecting opcode 0x6e at 0x0024

这个错误。在 Google 上搜索后,我找到了另一种解决方案,即

http://groups.google.com/group/android-developers/browse_thread/thread/368d0bae027aab63/1c61f007e821ed2a?q=%22Getting+the+state+of+a+checkbox+inside+of+a+listview%22+%22Romain+Guy%22#1c61f007e821ed2a

但我想在我的 onPrepareOptionMenu() Activity 中使用 SparseBooleanArray。如何从我的适配器中将此结果返回到我的 Activity 中。请给我建议?

最后我使用了 SparseBooleanArray。现在它工作正常。问候,安卓开发者

最佳答案

通过在我的自定义适配器中使用 SparseBooleanArray,解决了这个问题。

关于android - 如何处理listview android中的复选框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4848312/

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