

The third way is not a "true" implementation, but much simpler and clearer. Example2, as well as some other features built into the standard API.

The method is good because you get such goodies as methods: isChecked(), setChecked(), which you can apply to individual items "outside", for example, in an activity. The position is in key, its current state is in value. To get checked items, use the ListView 's getCheckedItemPositions() method ( getCheckedItemIds() as an option ), which returns a SparseBooleanArray containing the position numbers that were changed. In addition to differences in implementation, these methods also differ in the ways of obtaining the values of checkboxes (and this is what everything was started for). When changing a checkbox, write the new state to this list when creating items in the getView() method, force checkbox values to be set from this list.

Ĭreate a custom adapter that will store the states (set or not – for example, a separate boolean array or a field in the model for an item) of all checkboxes in the list. This markup must implement the Checkable interface. This option saddens the ascetic design – a line of text and opposite the checkbox.įollow the example of the first option, but create your own markup. Use the standard API features – set the list mode android:choiceMode="multipleChoice" (alternative code tChoiceMode(ListView.CHOICE_MODE_MULTIPLE) ) and use the markup provided by the API as an item – android.R.layout.simple_list_item_multiple_choice. There are three ways to implement checkboxes in a ListView : What can be done to save everything? Answer: Scrolling removes the checked status from hidden elements. The ListView has more items than will fit on the screen.
