0

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.

Kanth
  • 6,681
  • 3
  • 29
  • 41
Aksiom
  • 1,565
  • 4
  • 25
  • 39
  • in this layout its checkedtextview anyway store your checkbox state one array & user checkbox.setChecked(states[pos]); where states will be boolean array – Vishal Pawar Dec 21 '12 at 11:13

1 Answers1

2

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);
}
etienne
  • 3,146
  • 1
  • 24
  • 45
  • 1
    You should get the list adapater count once, and also not call getListView() multiple times. Do these prior to the for loop. – Stealth Rabbi Aug 06 '14 at 12:14