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 8566691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:42:46+00:00 2026-06-11T17:42:46+00:00

i am designing application in which i want to allow user to select multiple

  • 0

i am designing application in which i want to allow user to select multiple contact to send messages to. I have successfully retrieved the list of user in the listview with checkbox using the following code. now i want that when the user clicks on the “DONE” button, the PHONE NUMBER of the all selected contact should be retrieved in EDITTEXT in format like John <+919898xxxxxx>, Rick <+919988xxxxxx> and also that all the phone numbers containing just 10 digits i.e “9898xxxxxx” should be stored in a string seperated by comma (9898xxxxxx, 9988xxxxxx) automatically. how can i accomplish the requirement.

public class ContactsActivity extends ListActivity {

protected static final String TAG = null;
public String[] Contacts = {};
public int[] to = {};
public ListView myListView;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_contacts);
    final Button done_Button = (Button) findViewById(R.id.done_Button);
    final Button clear_Button =(Button) findViewById(R.id.clear_Button);
    Cursor mCursor = getContacts();
    startManagingCursor(mCursor);
    ListAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_multiple_choice, mCursor,
            Contacts = new String[] {ContactsContract.Contacts.DISPLAY_NAME },
            to = new int[] { android.R.id.text1 });
    setListAdapter(adapter);
    myListView = getListView();
    myListView.setItemsCanFocus(false);
    myListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    clear_Button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Toast.makeText(getApplicationContext(),"Selections Cleared", Toast.LENGTH_SHORT).show();
            ClearSelections();
        }
    });

    /** When 'Done' Button Pushed: **/
    done_Button.setOnClickListener(new View.OnClickListener() {
        public void onClick (View v){
            Log.i(TAG,":Done Button Selected:");
            SparseBooleanArray selectedPositions = myListView.getCheckedItemPositions();
            Log.i(TAG,"Number of Checked Positions: " + selectedPositions.size());
            for (int i=0; i<selectedPositions.size(); i++) {
                if (selectedPositions.get(selectedPositions.keyAt(i)) == true) {
                    //do stuff

                }
            }
        }
    });
}

private void ClearSelections() {
    int count = this.myListView.getAdapter().getCount();
    for (int i = 0; i < count; i++) {
        this.myListView.setItemChecked(i, false);
    }
}

private Cursor getContacts() {
    // Run query
    Uri uri = ContactsContract.Contacts.CONTENT_URI;
    String[] projection = new String[] { ContactsContract.Contacts._ID,
                                    ContactsContract.Contacts.DISPLAY_NAME};
    String selection = ContactsContract.Contacts.HAS_PHONE_NUMBER + " = '"
            + ("1") + "'";
    String[] selectionArgs = null;
    String sortOrder = ContactsContract.Contacts.DISPLAY_NAME
            + " COLLATE LOCALIZED ASC";

    return managedQuery(uri, projection, selection, selectionArgs,
            sortOrder);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_contacts, menu);
    return true;
}
}
  • 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-11T17:42:47+00:00Added an answer on June 11, 2026 at 5:42 pm

    configured it finally

            done_Button.setOnClickListener(new View.OnClickListener() {
            public void onClick (View v){
                String name = null;
                String number = null;
                long [] ids = myListView.getCheckedItemIds();
                for(long id : ids) {
                    Cursor contact = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, 
                            ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", new String[] { id + "" }, null);
                    while(contact.moveToNext()){
                        name = contact.getString(contact.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
                        //name+=name;
                        number = contact.getString(contact.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                        //number+=number;
                    }
                    Toast.makeText(getApplicationContext(), "Name: " +name + "\n" + "Number: " + number , Toast.LENGTH_LONG).show();
                }
            }
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am designing a silverlight application in which i want to level of user
I am in the process of designing a web application which will have multiple
I'm currently designing an application which I will ultimately want to move to Windows
I'm designing an application which will have a network interface for feeding out large
We are designing a Stress Test Application which will send mass HTTP requests of
We are designing an online application (college admission form) which mandates the user to
I'm designing a Java application using SWT. I have some tables which will display
I have made one windows phone based application. i want some designing ideas from
I am designing an android application for which I want to use web view
I am designing an application in which i have a table view controller. Now

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.