how to select multiple item in ListView in android.
+1
A:
You cannot "select" multiple items in a ListView
. You can use CHOICE_MODE_MULTIPLE
and check multiple items in a ListView
.
CommonsWare
2009-09-01 18:18:39
+3
A:
Actually you can ;) It's just a matter of user experience, right?
Try this, (1) for list control set
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
listView.setItemsCanFocus(false);
(2) define list item as
<CheckedTextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"
android:paddingLeft="6dip"
android:paddingRight="6dip"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
android:background="@drawable/txt_view_bg"
/>
This is same as "android.R.layout.simple_list_item_multiple_choice" except "android:background="@drawable/txt_view_bg"
(3) And define drawable txt_view_bg.xml as
<item android:drawable="@drawable/selected"
android:state_checked="true" />
<item android:drawable="@drawable/not_selected" />
Note:- The preferred way to handle multiple choice is to track choices your-self with on click item click, rather than depending on its state in list.
bhatt4982
2009-09-02 13:23:33