BigBen3216
BigBen3216

Reputation: 867

ListView choice mode

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">

Upvotes: 3

Views: 11920

Answers (1)

ebarrenechea
ebarrenechea

Reputation: 3785

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.

Upvotes: 3

Related Questions