how to handle checkbox in listview android?
I am using checkbox with ListView.Code is working fine. I strucked to get all the list checked Items. I used below code for getting checked items. But it is giving result of focused area of list.
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
}
}
}
But it is giving o开发者_如何学Pythonnly focusable list items result only.Depending on sublist I want to populate my menu that's why I am using this code in onPrepareOptionsMen() method and clicking on menu item delete this list from database. I found another solution that is
long checkedPos[] =list.getCheckedItemIds();
But it is giving
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
This error. After searching on Google I found another solution that is
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
but I want to use SparseBooleanArray into my activity onPrepareOptionMenu().How to get back this result into my activity from my adapter.Please give me advice?
At last i used SparseBooleanArray.Now it is working fine. Regards, Android developer
By using SparseBooleanArray in my custom adapter, solved this problem.
精彩评论