1

I am using a customized list view, as shown below:

list_item.xml file:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16sp"
android:background="#ffffff" 
android:textColor="#000000">

Activity file extending ListActivity:

  @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, COUNTRIES));       
    ListView lv = getListView();
    lv.setTextFilterEnabled(true);

We use this code for multiple list item selection:

 setListAdapter(new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_multiple_choice,
            hometown));

But I have changed the 2nd argument of ArrayAdapter to a customized TextView, hence i dont understand where to put the option for multiple choice of list items.

Please help

Regards,

user182944
  • 7,897
  • 33
  • 108
  • 174

1 Answers1

0
 lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

you can use the above line below

ListView lv = getListView();

Updated::

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
 <TextView android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:padding="10dp"
    android:textSize="16sp"
    android:background="#ffffff" 
    android:layout_alignParentLeft="true"
    android:textColor="#000000">
 <CheckBox android:id="@+id/checkbox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"    
    android:text="check it out" />
</RelativeLayout>

use these xml file instead of yours and replace this adapter in your code

new ArrayAdapter<String>(this, R.layout.list_item, COUNTRIES,new Int[] {R.id.textview1})
Shankar Agarwal
  • 34,573
  • 7
  • 66
  • 64
  • Hi, I tried the option you suggested but it is not working. No checkbox appears beside the Items present in the ListView. Please suggest – user182944 Apr 28 '12 at 03:14
  • i got a class cast exception:Caused by: java.lang.ClassCastException: android.widget.RelativeLayout cannot be cast to android.widget.TextView – user182944 Apr 28 '12 at 03:27
  • simply use setListAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_multiple_choice, COUNTRIES)); – Shankar Agarwal Apr 28 '12 at 03:35
  • http://www.ezzylearning.com/tutorial.aspx?tid=1763429&q=customizing-android-listview-items-with-custom-arrayadapter – Shankar Agarwal Apr 28 '12 at 03:38