android - MultiAutoCompleteText contacts -


i want multiautocompletetextview this:

i can retrieve contacts numbers in array , names in array. how can multiautocompletetextview? example, in picture if enter ca there suggestion , if enter 22, there same suggestion, , under other. have 2 arrays numbers[] , names[], multiautocompletetextview.

here code:

cursor phones = getcontentresolver().query(contactscontract.commondatakinds.phone.content_uri, null,null,null, null); arraylist<string> numbers = new arraylist<string>(); arraylist<string> names = new arraylist<string>();  while (phones.movetonext()) {      names.add(phones.getstring(phones.getcolumnindex(contactscontract.commondatakinds.phone.display_name)));      numbers.add(phones.getstring(phones.getcolumnindex(contactscontract.commondatakinds.phone.number))); } phones.close(); string[] numbersarray = new string[numbers.size()]; string[] namesarray = new string[names.size()]; numbers.toarray(numbersarray); names.toarray(namesarray); arrayadapter<string> adapter = new arrayadapter<string>(this,          android.r.layout.simple_dropdown_item_1line, namesarray); multiautocompletetextview textview = (multiautocompletetextview)findviewbyid(r.id.edt_numara);  textview.settokenizer(new multiautocompletetextview.commatokenizer()); textview.setadapter(adapter); 

but works names , numbers isn't showing.

step 1. create autocomplete in xml file shown below

<autocompletetextview android:paddingtop="15dp" android:id="@+id/txtphoneno" android:focusableintouchmode="true" android:layout_width="fill_parent" android:layout_height="wrap_content" android:imeoptions="actiondone"/> 

step 2. add following permission in android mainfeast file accessing contacts

<uses-permission android:name="android.permission.read_contacts" /> 

step 3. create activity , maps autocompletetextview component in java code

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);  } 

step 4: use contentreslover fetch contacts, if running in android 1.6 or before version use people class fetching contacts , add contacts in array list shown below

contentresolver cr1 = getcontentresolver();  string[] projection = new string[] { people._id,people.name,people.number };  uri phone_contacts = people.content_uri;  cursor managedcursor = cr1.query(phone_contacts, projection, null, null, people.name + " asc");  if (managedcursor.movetofirst()) {  string contactname; string cphonenumber; int namecolumn = managedcursor.getcolumnindex(people.name); int phonecolumn = managedcursor.getcolumnindex(people.number); log.d("int name",integer.tostring(namecolumn)); log.d("int number",integer.tostring(phonecolumn));   { // field values contactname = managedcursor.getstring(namecolumn); cphonenumber = managedcursor.getstring(phonecolumn); if((contactname != " " || contactname != null) && (cphonenumber!= " " ||cphonenumber!= null)) {  c_name.add(contactname); c_number.add(cphonenumber); }   } while (managedcursor.movetonext());  }   // donot use people class if using android1.6 above  uri contacts = uri.parse("content://icc/adn");  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));   { // 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());  } 

step 5: convert arraylist array , set array autocomplete shown below

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); 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -