Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Listview - can not select multiple items when using a cursor
    primarykey
    data
    text
    <p>I have a listview populated with data from a cursor using SimpleCursorAdapter. I want to make it so I can select multiple items with a checkbox against each item but I can only get it to check a single item at a time i.e. each time I select an item, it will clear the currently selected item.</p> <p>It works fine if I populate the listview using an ArrayAdapter. I can select multiple items. So I dont know why it doesn't work with the SimpleCursorAdapter.</p> <p>This is being created in a DialogFragment if that matters.</p> <p>Really pulling my hair out on this, pleae help!!</p> <p>Here's the code:</p> <pre><code>Cursor attributesCursor = mDBHelper.getItemAttributesbyType(menuID, itemID, "M"); getActivity().startManagingCursor(attributesCursor); ListView lv = new ListView(this.getActivity()); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.MATCH_PARENT); lv.setLayoutParams(params); SimpleCursorAdapter adapter = new SimpleCursorAdapter( getActivity(), android.R.layout.simple_list_item_multiple_choice, attributesCursor, new String[] { "AttributeDescription" }, new int[] { android.R.id.text1 },0); attributesLinearLayout.addView(lv); lv.setAdapter(adapter); lv.setItemsCanFocus(false); lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); </code></pre> <p>Edit : Just to add some extra info, the multi choice listview works if i use this code, where "items" is a simple String array:</p> <pre><code>lv.setAdapter(new ArrayAdapter(this.getActivity(), android.R.layout.simple_list_item_multiple_choice, items)); </code></pre> <p>Also, this listview is being dynamically added to an existing Linearlayout (attributesLinearLayout) in a dialogfragment which contains other controls. I also tried extending other adapters, including the array adapter and customer item layouts but that again didnt allow me to select multiple items.</p> <p>Please help!!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload