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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:57:44+00:00 2026-05-28T19:57:44+00:00

I am having making my edittext field autocomplete for contacts phone numbers. I know

  • 0

I am having making my edittext field autocomplete for contacts phone numbers. I know how to get contacts from database and display them in text field but i need them to autocomplete just incase the user wants to type a name into textfield. I understand how to get an array to auto complete and the whole theory behind that. But how to pull from phone contacts is difficult. I’ve seen many tutorials and also various question on stack overflow, but still kind of stumped. A code snippit would help please.

public class MyContacts extends Activity {

    AutoCompleteTextView txtPhoneNo;

    public ArrayList<String> c_Name = new ArrayList<String>();
    public ArrayList<String> c_Number = new ArrayList<String>();
    String[] name_Val = null;
    String[] phone_Val = null;

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        txtPhoneNo = (AutoCompleteTextView) findViewById(R.id.txtPhoneNo);

    }

    Uri contacts = Uri.parse("content://icc/adn");
    ContentResolver cr = getContentResolver();

    Cursor managedCursor1 = cr.query(contacts, null, null, null, null);
    {
        if (managedCursor1.moveToFirst()) {

            String contactname;
            String cphoneNumber;

            int nameColumn = managedCursor1.getColumnIndex("name");
            int phoneColumn = managedCursor1.getColumnIndex("number");

            Log.d("int Name", Integer.toString(nameColumn));
            Log.d("int Number", Integer.toString(phoneColumn));

            do {
                // Get the field values
                contactname = managedCursor1.getString(nameColumn);
                cphoneNumber = managedCursor1.getString(phoneColumn);
                if ((contactname != " " || contactname != null)
                        && (cphoneNumber != " " || cphoneNumber != null)) {

                    c_Name.add(contactname);
                    c_Number.add(cphoneNumber);
                }

            } while (managedCursor1.moveToNext());
        }
        name_Val = (String[]) c_Name.toArray(new String[c_Name.size()]);
        phone_Val = (String[]) c_Number.toArray(new String[c_Name.size()]);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_dropdown_item_1line, name_Val);
        txtPhoneNo.setAdapter(adapter);
    }
}

My code… no compile errors but still does not work

  • 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-28T19:57:45+00:00Added an answer on May 28, 2026 at 7:57 pm

    Better would be to fetch the Contacts and store it in ArrayList. Then you can just bind the ArrayList with the AutoComplete TextView. Then the rest of the part is just easy to filter the ArrayList when you the user types in the AutoComplete TextView.

    UPDATE

    You can create a POJO Class with getter-setter of contact_name and contact_number. Then create List<POJO> list = new ArrayList<POJO>();. Then just add the contact_name and contact_number to the list using POJO class

    POJO pojo_obj = new POJO();
    pojo_obj.setcontact_name(contactname);
    pojo_obj.setcontact_number(cphoneNumber);
    list.add(pojo_obj);
    

    And finally set this list to the Adapter.

    And then in the Adapter class you can set it to the TextView using

    list.get(position).getcontact_name();
    list.get(position).getcontact_number();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a website for my church and I'm having problems making it display
I'm having trouble making a connection to Amazons RDS service from my Codeigniter application.
I'm having trouble making a JMenuItem in one class pull up a JTree from
I'm using grep to extract parts from a file but I'm having trouble making
Im having trouble making my table contents vertically aligned and was wondering if you
Im having trouble making sure my active graphic is positioned outside of the button,
I'm having problems making a ComboBox stretch to fill the whole column width in
I'm having trouble making a secure FTP connection using SharpSSH. Up to now I've
I'm having difficulty making a dynamic AJAX form submition method for .NET WebServices. The
I'm having problems making Lua & Luabind work under Windows 7 using VS 2010.

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.