Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i toggle the checked state of items in a ListView?

I know it is possible to graphically toggle the checked state of an item in a ListView. But how is this done? I have a ListView containing several CheckedTextView items, and I've tried setting the checked state of these items by calling

list.setItemChecked(arg2, false);

and respectively

list.setItemChecked(arg2, true);

This is called in the OnItemClickedListener of my ListView, so the arg2 is the index of the item clicked. Nevertheless, the item doesn't get checked. Is there a call to the listAdapter that I'm missing? Or what could this be?

like image 630
ThaMe90 Avatar asked Feb 01 '26 07:02

ThaMe90


1 Answers

What layout are you using for the ListItems? android.R.layout.simple_list_item_multiple_choice?

Your android:choiceMode also has to be set to either singleChoice or multipleChoice.

like image 154
Robby Pond Avatar answered Feb 03 '26 19:02

Robby Pond



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!