Skip to content Skip to sidebar Skip to footer

Checkbox In Listview With Custom Simplecurser Binding

i think ive tried everything(made focusable:false!!) and i cant capture in anyway the selected checkbox on my list item. even OnItemClickListener, doesnt respond to any click. how

Solution 1:

I would recommend you use Android's built-in support for multiple-choice lists (CHOICE_MODE_MULTIPLE).

The List11.java SDK sample demonstrates this. You can also find a project from one of my tutorials that uses it here.

You can still use this technique with your own layout, so long as you include a CheckedTextView with android:id="@android:id/text1" as shown in the android.R.layout.simple_list_item_multiple_choice resource, a copy of which ships with your SDK.

Solution 2:

Solution 3:

I want also to select one item in the list (no CHOICE_MODE_MULTIPLE) and retrieve the states of the checkboxes. In my custom ListAdapter, I implemented something like :

privatevoidbindView(int position, View view) {
      finalCheckBoxmyCheckBox= (CheckBox)view.findViewById(R.id.my_checkbox);

      finalMyObjectmyModelObject= (MyObject)getItem(position);

      myCheckBox.setOnCheckedChangeListener(newOnCheckedChangeListener() {
        @OverridepublicvoidonCheckedChanged(CompoundButton buttonView, boolean isChecked) {
          myModelObject.setSelected(isChecked);
        }
    });

And in onItemClick() listener of the ListView, I can retrieve the checkboxes states with :

((MyObject)listView.getAdapter().getItem(n)).isSelected()

Post a Comment for "Checkbox In Listview With Custom Simplecurser Binding"