Checkbox In Listview With Custom Simplecurser Binding
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:
http://www.coderanch.com/t/513608/Android/Mobile/Multiple-Checkboxes-ListView
check this example it is very good example for custom listview with checkbox.
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"