Search code examples
androidlistviewcheckboxmultiple-choice

check checbox programmatically in multiple_choice listview (android)


sorry if there is another question like this but i couldn't find my answer.

I want to know the way to programmatically set a checkbox to state where it is already selected when I populate the ListView. The checkbox is in the Listview and i am using android.R.layout.simple_list_item_multiple_choice.

Any help would be nice, thank you.


Solution

  • There is a method on ListView that you can call to set an item 'checked' state:

    for (int i = 0; i < getListAdapter().getCount(); i++) {
        getListView().setItemChecked(i, true);
    }