Pages

Wednesday, May 19, 2010

Android ListView Multiple Choice Example

In android listview we can able to select more then one option at a time in list.
Here is a simple example for how to select more then one option from list.
Multiple Choice ListView Example :-

****************************************
xml file




xml version="1.0" encoding="utf-8"?>
2<LinearLayout android:id="@+id/LinearLayout01"
3    android:layout_width="fill_parent" android:layout_height="fill_parent"
4    xmlns:android="http://schemas.android.com/apk/res/android">
5    <ListView android:id="@+id/ListView01" android:layout_height="wrap_content"
6        android:layout_width="fill_parent">ListView>
7LinearLayout>
******************************
Java file

public class ListViewMultipleChoiceExample extends Activity {
02    private ListView lView;
03    private String lv_items[] = { "Android""iPhone""BlackBerry",
04            "AndroidPeople""J2ME""Listview""ArrayAdapter""ListItem",
05            "Us""UK""India" };
06 
07    @Override
08    public void onCreate(Bundle icicle) {
09        super.onCreate(icicle);
10        setContentView(R.layout.main);
11        lView = (ListView) findViewById(R.id.ListView01);
12//      Set option as Multiple Choice. So that user can able to select more the one option from list
13        lView.setAdapter(new ArrayAdapter(this,
14                android.R.layout.simple_list_item_multiple_choice, lv_items));
15        lView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
16    }
17}

******************************
output :

1 comment: