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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:06:27+00:00 2026-05-27T20:06:27+00:00

I have some contacts autocomplete and autosearch algorithm working for my android app. First

  • 0

I have some contacts autocomplete and autosearch algorithm working for my android app.
First some xml to define the text view for the input:

<AutoCompleteTextView
        a:id="@+id/recipientBody"
        a:layout_width="0dip"
        a:layout_height="wrap_content"
        a:layout_weight="1.0"
        a:nextFocusRight="@+id/smsRecipientButton"
        a:hint="@string/sms_to_whom"
        a:maxLines="10"
       />

And now I setup the text view

AutoCompleteTextView recip =
        (AutoCompleteTextView) findViewById(R.id.recipientBody);

ArrayAdapter<String> adapter = 
new ArrayAdapter<String>(this, R.layout.list_item, getAllContacts());
        recip.setAdapter(adapter);

And now the actual algorithm that searches for a contact that matches the input:

private List<String> getAllContacts() {
        List<String> contacts = new ArrayList<String>();
        ContentResolver cr = getContentResolver();
        Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);

        if (cursor.getCount() > 0) {
            while (cursor.moveToNext()) {
                String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
                String displayName = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));

                if (Integer.parseInt(cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
                    Cursor pCursor = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, 
                                            null, 
                                            ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?", 
                                            new String[]{contactId}, null);

                    while (pCursor.moveToNext()) {
                        String phoneNumber = pCursor.getString(pCursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));                      
                        contacts.add(phoneNumber + " ( " + displayName + " )");
                    } 

                    pCursor.close();
                }
            }
        }       
        return contacts;
    }

This works fine for both contact number and name input. But there is still a problem. The user can input multiple phone numbers. But when one contact is applied to the text view it cannot search again, because the algorithm takes the whole string.

How can I solve that?

  • 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-05-27T20:06:27+00:00Added an answer on May 27, 2026 at 8:06 pm

    EDIT:

    Well, I thought about it for a while and spotted a problem with my solution – there’s no place where you could insert the contact from the completion list into the TextView.

    The solution seems to be MultiAutoCompleteTextView, this thing is designed for solving your problem.

    Sorry for confusion!


    For me, it looks like you need a custom adapter.

    You may extend ArrayAdapter<String> and implement getFilter() – of course you will also need a custom filter (extending Filter) which instance you will return from that method.

    Filter’s performFiltering method has one parameter – the string for which the list of suggestion is needed. You need to take the part after the last comma (or whatever character are you using as a separator) and return the suggestion list for that substring.

    P.S.

    For the better user experience, you may also think of styling your AutoCompleteTextView contents with Spans: http://ballardhack.wordpress.com/2011/07/25/customizing-the-android-edittext-behavior-with-spans/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created some tables with text fields inside, like in the contacts for
I'm trying to add some contacts from an xml file which have been serialize
We have some input data that sometimes appears with &nbsp characters on the end.
I have some code like this in a winforms app I was writing to
I have created some contacts data in the emulator. When I run the ContactManager
I have created a polymorphic association around a model called status. Some contacts will
i have some index.php page.. after download jquery drop down menu,the link text like
Do you know how to have some cells appear in a table view after
I have an XML file : <?xml version=1.0 encoding=windows-1250?> <CONTACTS> <CONTACT> <FirstName>AfgZohal</FirstName> <LastName>Zohal Afg</LastName>
I have an app, where I generate text (about 500 characters), and I would

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.