Search code examples
androidlistviewandroid-listviewandroid-fragmentsandroid-listfragment

Select multiple items in ListFragment


How do you set the ListView in a ListFragment to multiple choice? In a standard activity, I would specify android:choiceMode="multipleChoice" in the xml file, and use android.R.layout.simple_list_item_activated_1 as the textViewResourceId while attaching the adapter and all works fine, but in the ListFragment, the items selected are not being highlighted as they should with android.R.layout.simple_list_item_activated_1 and the choice mode is singleChocie.


Solution

  • How do you set the ListView in a ListFragment to multiple choice?

    getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE) from Java, or provide your own layout file that uses android:choiceMode="multipleChoice" in the ListView, in addition to your adapter setup.