Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8512397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:16:10+00:00 2026-06-11T04:16:10+00:00

I’m having problems with setting multiple choice selection in ListView. My ListView has contacts’

  • 0

I’m having problems with setting multiple choice selection in ListView. My ListView has contacts’ names which are retrieved from the android phone.

I’ve followed examples on setting multiple choice but it didn’t work out.

I’ve tried typing

SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.contacts_list, c, columns, views);
        list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
        this.setListAdapter(adapter);

but I don’t see the checkbox in the ListView.

And I’ve replaced R.layout.contacts_list with android.R.layout.simple_list_item_multiple_choice and it showed checkboxes but no names from the android phone’s contacts.

Here are my codes:
contacts_list.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="@color/light_goldenrod"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:stackFromBottom="false"
        android:transcriptMode="normal"
        android:choiceMode="multipleChoice" >
    </ListView>

    <TextView
        android:textColor="@color/dark_purple"
        android:id="@+id/contactName"
        android:textStyle="bold"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

ContactsList.java

public class ContactsList extends ListActivity
{
    final Context context = this;

    Cursor cursor;

    String[] buddiesList = 
        {"Kanak Priya",
        "Joanne Liew",
        "Michelle Lam",
        "Teo Kin Hua",
        "Melissa Haiting",
        "David Yeo",
        "Natasha Akhbar",
        "Gillian Gan",
        "Sonia",
        "Ms Long",
        "Joan Tang",
        "Stephanie",
        "Nur Ashiqin"
        };

    BuddyDBAdapter buddyDB = new BuddyDBAdapter(this);

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.contacts_list);

        ListView list = getListView();



        setListAdapter(new ArrayAdapter<String> (this, R.layout.contacts_list, R.id.contactName, buddiesList));

        Uri allContacts = Uri.parse("content://contacts/people");

        Cursor c = managedQuery(allContacts, null, null, null, null);

        String[] columns = new String[] {ContactsContract.Contacts.DISPLAY_NAME};
        int[] views = new int[]  {R.id.contactName};

        startManagingCursor(c);

        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.contacts_list, c, columns, views);
        list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
        this.setListAdapter(adapter);


        /*if(cursor.getCount()<0)
        {
            Intent displayIntent = new Intent(Intent.ACTION_VIEW);
            displayIntent.setData(Uri.parse("content://contacts/people"));
            startActivity(displayIntent);

            displayIntent = new Intent(Intent.ACTION_VIEW);
            //displayIntent.setData(Uri.parse("content://contacts/people/"+id));
            startActivity(displayIntent);
        }
        else
        {
            final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
            alertDialog.setTitle("ALERT!");
            alertDialog.setMessage("NO Name is Found! D:");
            alertDialog.setIcon(R.drawable.warning);
            alertDialog.setButton("OK", new DialogInterface.OnClickListener()
            {
                public void onClick(DialogInterface dialog, int which)
                {
                    Intent backIntent = new Intent(context, ContactsList.class);
                    startActivity(backIntent);
                }
            });
            alertDialog.show();
        }*/
    }

    @Override
    public void onListItemClick(ListView l, View v, int position, long id)
    {
        buddyDB.open();
        long name_id;
        super.onListItemClick(l, v, position, id);


        Cursor c = ((SimpleCursorAdapter)l.getAdapter()).getCursor();

        TextView contactName = (TextView) v.findViewById(R.id.contactName);
        String NameValue = contactName.getText().toString();

        name_id = buddyDB.insertNames(NameValue);


        Toast.makeText(getBaseContext(),
                "Selected: " + buddiesList[position], Toast.LENGTH_SHORT).show();


        buddyDB.close();

Oh by the way, the

String[] buddiesList = 
        {"Kanak Priya",
        "Joanne Liew",
        "Michelle Lam",
        "Teo Kin Hua",
        "Melissa Haiting",
        "David Yeo",
        "Natasha Akhbar",
        "Gillian Gan",
        "Sonia",
        "Ms Long",
        "Joan Tang",
        "Stephanie",
        "Nur Ashiqin"
        };

is for my Toast message.

I really need help with this. Any help will be appreciated. Examples will be greatly appreciated too.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T04:16:11+00:00Added an answer on June 11, 2026 at 4:16 am

    You may have two choices:

    1 – Use default layout from Android resources (simple_list_item_multiple_choice)

    you may replace this code:

    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,R.layout.contacts_list, c, columns, views);
    

    to:

    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_multiple_choice, c, columns, new int {android.R.id.text1});
    

    2 – Create your new row layout contains your defined checkbox and handle it by your own.

    contact_list.xml

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:background="@color/light_goldenrod"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
        <ListView
            android:id="@android:id/list"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:stackFromBottom="false"
            android:transcriptMode="normal"
            android:choiceMode="multipleChoice" >
        </ListView>
    </LinearLayout>
    

    contact_entry.xml

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content">
        <TextView
            android:textColor="@color/dark_purple"
            android:id="@+id/contactName"
            android:textStyle="bold"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <CheckBox
            android:id="@+id/contactCheckbox"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text=""
            android:checked="false" />
    
    </LinearLayout>
    

    Add custom cursor adapter like this:

    public class YourCursorAdapter extends CursorAdapter  {
    
    private Context mContext;
    private Cursor mCurser;
    
    public YourCursorAdapter(Context context, int layout, Cursor c, String[] from,
            int[] to, ContentResolver co) {
        super(context, c);
        mCurser = c;
        mContext = context;
    }
    
    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        // TODO Auto-generated method stub
        LayoutInflater inflater = LayoutInflater.from(mContext);
        View v = inflater.inflate(R.layout.contact_entry, parent, false);
        bindView(v, mContext, cursor);
        return v;
    }
    
    @Override
    public void bindView(View view, Context context, Cursor cursor) {
    
        TextView contactName= (TextView)view.findViewById(R.id.contactName);
        contactName.setText(cursor.getString((mCurser
                .getColumnIndexOrThrow(Contacts.Phones.DISPLAY_NAME))));
        CheckBox contactCheckbox = (TextView)view.findViewById(R.id.contactCheckbox);
        contactCheckbox.setOnClickListener(new OnClickListener() {
    
            @Override
            public void onClick(View v) {
                Checkbox checkBox = (Checkbox) v.findViewById(R.id.contactCheckbox)
                if (checkBox.isChecked())
                        checkBox.setChecked(false);
                else
                        checkBox.setChecked(true);
            }
        });
    }
    

    in your ListActivity:

        YourCursorAdapter adapter = new YourCursorAdapter(this,
                null, c, null, null,null);
        this.setListAdapter(adapter);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.