Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListView choice mode

Tags:

android

Can anybody tell me why when i set this property to my ListView:

mList.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

The items on the list seems to reload anytime I click on one of them? If i remove that property that behaviour doesn´t show up.

I'm setting this in the OnCreateView method of my activity, I could also set this up in my xml getting the same result:

<ListView
        android:id="@+id/lista"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="@string/per_lista"
        android:fadingEdge="none"
        android:divider="#e2e2e2"
        android:dividerHeight="1dp"
        android:choiceMode="singleChoice">
like image 514
BigBen3216 Avatar asked Aug 12 '26 05:08

BigBen3216


1 Answers

Every time an item is checked/unchecked the ListView calls requestLayout() which causes its children to be redrawn. It doesn't mean the items are being reloaded, though. If your items are being reloaded then we'll need more information. Just in case you want to have a look, the ListView source can be found here.

Unfortunately I don't know and I'm not even sure you can avoid the list items being redrawn. It's the intended behaviour since the items are being redrawn so that their selected state can be set or reset according to the selection. You could always use the source code as a basis for your own custom ListView that doesn't request a layout pass/redraw after its selection state changes.

like image 169
ebarrenechea Avatar answered Aug 14 '26 18:08

ebarrenechea



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!