1

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 only 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

3
  • D'you set choiceMode to something defferent than CHOICE_MODE_NONE (see setChoiceMode docs) Commented Jan 31, 2011 at 7:06
  • I defaut one is not usable in my case that's why I used customised list Commented Jan 31, 2011 at 7:48
  • At last i used SparseBooleanArray and it is working fine Commented Feb 10, 2011 at 10:08

1 Answer 1

1

By using SparseBooleanArray in my custom adapter, solved this problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.