android - Autocomplete Contacts and add to ListView -


I am creating an application, in the name of a contact through a AutoCompleteTextView , then after selecting the contact, I want to add that contact to a ListView So far, I have been successful in getting contact names, phone numbers and types via autocomplete with this code:

  Public class enhances UserContactActivity activity {Private ArrayList & lt; Maps & lt; String, string & gt; & Gt; MPeopleList; Private Simple Adapter mAdapter; Private autocomplete text message mTxtPhoneNo; /** Called when the activity is first created. * / @ Override Crate on Public Zero (Bundle Saved Instantstate) {Super. Contents (Saved Instantstate); SetContentView (R.layout.activity_user_contacts); MPeopleList = New Arrestist & lt; Maps & lt; String, string & gt; & Gt; (); PopulatePeopleList (); MTxtPhoneNo = (Autocomplete full view view) ViewById (R.id.mmWhoNo); MADAPTER = New simple adapter (this, ampleblowlist, R.layoutcastcentview, new string [] {"name", "phone", "type"}, new int [] {rdid.com, r.ind.ccctno , RID.COCT type}); MTxtPhoneNo.setAdapter (mAdapter); // This is the button that updates the user's emergency contacts list // button btnSimple = (button) findViewById (R.id.btnSimple); //btnSimple.setOnClickListener(new OnClickListener () {// See public void onClick (v) (// Contact //) says notifyDataSetChanged (;.} //} public void PopulatePeopleList () {mPeopleList.clear (); cursor people = getContentResolver () query (ContactsContract.Contacts.CONTENT_URI, null, null, null, null) ;. whereas (people.moveToNext ()) {string CONTACTNAME = people.getString (people.getColumnIndex (ContactsContract.Contacts.DISPLAY_NAME)) ; String contactId = people.getString (people.getColumnIndex (ContactsContract.Contacts._ID)); string hasPhone = people.getString (people.getColumnIndex (ContactsContract.Contacts.HAS_PHONE_NUMBER); if ((Integer.parseInt (hasPhone) gt ; 0)) {// You know so now is the number Cursor phone like this query = getContentResolver (). Query (ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContractkCommonDataKindskPhonekCONTACT_ID + "=" + ContactId, null, null); while (phones.moveToNext ()) {// Display the store numbers and the user who displays the dialog String Phononumber = PhonesGet String (Phone.Gate Column Index (ContactContact.com.CommentIndex.phone NUMBER)); String Number Type = PhonesGet String (Phone.Gate Column Index (ContactContact.comCommentIndonesphone.TYPE)); Maps & lt; String, string & gt; NamePhoneType = New Hashmap & lt; String, string & gt; (); NamePhoneType.put ("name", contact name); Type the namephone. ("Phone", phone number); If (number type.file ("0")) NamePhoneType.put ("type", "work"); Else if (numberType.equals ("1") NamePhoneType.put ("Type", "Home"); Else if (numberType.equals ("2") NamePhoneType.put ("Type", "Mobile"); Other Name PhoneType.put ("Type", "Other"); // Then add this map to the list. MPeopleList.add (NamePhoneType);} Phones.close ();}} People.close ();  < / Pre> 

Now I want to add the selected contact to an election list and just want to display their name and number. This is my current Java file array adapter And list :

  is the mainActivity activity with the public class Tar (Last ArrayList & LT; string & gt; call list = new Arrelist & lt; String & gt; (); Override public void on @Create (bundle saved Instansstet) {Suprknkret (saved Instensstet); setContentView (R.layout.activity_main); ListView myListView = (ListView) Search ViewById (R.id.myListView); final editing text my Adittakst = (editable text) searching for Viviaibiaiaidi (Arkaidkmei edit text); Last Array List & lt; String & gt; Phone List = New Arrestist & lt; String & gt; (); Last Array Adapter & lt; String & gt; come; Aa = new array adapter & lt; String & gt; (This, R.layout.custom_list_item, R.id.phoneName, phoneList); myListView.setAdapter (aa); Button btnSimple = (button) findViewById (R.id.btnSimple); btnSimple.setOnClickListener (add new OnClickListener () {public void onClick (View v) {// Contact Phone List. add (0, myEditText.getText (). toString ()); // Check for updates aa.notifyDataSetChanged (); / / MyEditText.setText ("");}}) to erase the text; }}   

Sorry if this is a simple question I am new to programming for Android, but it is trying to work for days

Instead of using an array adapter, you can use the base adapter and the pass. Your custom releaseview cell layout. Or expand the aradaptator in its own Koodam class. And inflate your layout.

For more information



Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -