0 down vote favorite
share [g+] share [fb] share [tw]
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.
It works fine if I populate the listview using a simple string
ArrayAdapter. I can select multiple items. So I dont know why it
doesn't work with the SimpleCursorAdapter.
This listview is being dynamically added to an existing Linearlayout
(attributesLinearLayout) in a dialogfragment which contains other
controls, if that matters.
Here's the 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);
***********************************************
the multi choice listview works if i use this code, where "items" is
a simple String array of text:
***********************************************
lv.setAdapter(new ArrayAdapter(this.getActivity(),
android.R.layout.simple_list_item_multiple_choice,
items));
***********************************************
I also tried extending other adapters, including the array adapter and
CursorAdapter using custom item layouts but that again didnt allow me
to select multiple items.
Please help!!
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en