Single Selection mode for ListView in Android

June 15, 2012

In this application, we are creating a listview with single selection mode. That is only one item can be selected at a time. This is achieved by adding a radio button on each item in the listview.

1. Create an Android Project namely “ListViewRadio”

New Android Project

1. New Android Project

2. Select a build target for this application. For this application let us selection Android 2.3.3 ( API level 10  )

Select Build Target

Figure 2: Select Build Target

3.  Enter application related details like package name, main activity class name etc

Application Details

Figure 3 : Application Details


4. Open and update the file /res/layout/main.xml with the given below code.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
    android:orientation="vertical" >



5. Open and update the file /src/in/wptrafficanalyzer/listviewradio/

package in.wptrafficanalyzer.listviewradio;

import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MainActivity extends Activity {
    String[] countries = new String[] {
        "Sri Lanka",
        "North Korea",
        "South Korea",

    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {

        // Getting object reference to listview of main.xml
        ListView listView = (ListView) findViewById(;

        // Instantiating array adapter to populate the listView
        // The layout android.R.layout.simple_list_item_single_choice creates radio button for each listview item
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_single_choice,countries);



6. Run the application in Android Virtual Device, by clicking the menu Run -> Run of the Eclipse IDE

Application in execution

Figure 4: Application in execution

7. Download

8. Reference

How to hire me?

I am George Mathew, working as software architect and Android app developer at

You can hire me on hourly basis or on project basis for Android applications development.

For hiring me, please mail your requirements to

My other blogs

Android Knowledge Quiz

Ready to test your knowledge in Android? Take this quiz :


3 Responses to Single Selection mode for ListView in Android

  1. sunil pal on August 27, 2012 at 4:05 pm

    String[] countries = new String[] {
    in the dotted area i want it to show email messages in list view how can i do it please tell me

  2. khaled on May 17, 2013 at 12:26 am

    How to make the first one selected when the list view is firs initiated?

  3. divya on February 10, 2016 at 6:57 pm

    how can i achieve this single selection in listview using expandable listveiw?

Leave a Reply to sunil pal Cancel reply

Your email address will not be published. Required fields are marked *

Be friend at g+

Subscribe for Lastest Updates

FBFPowered by ®Google Feedburner