android - Contact name and phone number in an EditText - filtered typing -


what want have edittext, there can type name (so appears filtered list names correspond have typed far). choose contact. edittext shall display name had chosen, send message (sms) number corresponds contact chosen.

here code, not complete: of course have settings in androidmanifest file..

public class sendsmsactivity extends activity {

button buttonsend; edittext textphoneno; edittext textsms; string sms =""; listadapter ladapter;  @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.sendsms);      buttonsend = (button) findviewbyid(r.id.buttonsend);     textphoneno = (edittext) findviewbyid(r.id.edittextphoneno);             textphoneno.addtextchangedlistener(new textwatcher() {          @override         public void ontextchanged(charsequence s, int start, int before, int count) {             // todo auto-generated method stub             string srchname = textphoneno.gettext().tostring();             cursor cursor = getcontentresolver().query(                     contactscontract.contacts.content_uri,                     null,                     contactscontract.contacts.has_phone_number                             + " = 1 , "                             + contactscontract.contacts.display_name                             + " " + "'" + srchname + "%'",                     null,                     "upper(" + contactscontract.contacts.display_name                             + ") asc");             startmanagingcursor(cursor);              load(cursor);         }          @override         public void beforetextchanged(charsequence s, int start, int count,                 int after) {             // todo auto-generated method stub          }          @override         public void aftertextchanged(editable s) {             // todo auto-generated method stub          }     });     textsms = (edittext) findviewbyid(r.id.edittextsms);      sms = mainactivityclass.tempsms.tostring();     log.d("sendsmsactivity", " sms text = " + sms);     textsms.settext(sms);     textsms.setvisibility(edittext.visible);      buttonsend.setonclicklistener(new onclicklistener() {          @override         public void onclick(view v) {              string phoneno = textphoneno.gettext().tostring();             //string sms = textsms.gettext().tostring();               try {                 smsmanager smsmanager = smsmanager.getdefault();                 smsmanager.sendtextmessage(phoneno, null, sms, null, null);                 toast.maketext(getapplicationcontext(), "sms sent!",                         toast.length_long).show();             } catch (exception e) {                 toast.maketext(getapplicationcontext(),                         "sms faild, please try again later!",                         toast.length_long).show();                 e.printstacktrace();             }          } });  } 

}

i don't know have tried moment give points of thoughts:

  1. create own contact class have name , phone members.
  2. iterate cursor in contact list , each iterate create new contact name , phone received contact list.
  3. when create new contact store list (i mean list : list<contact> contacts = new arraylist<contact>(); )
  4. this list stored on list adapter
  5. when type on edittext check if there contact contains same chracters

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -