android - how do i put my contacts into edittext? -
good day!
i newbie in programming , trying learn new things. explain question have button looks contact , clicking contact app display number in toast. can't understand yet how make text display in edittext.
here code.
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_s); ((button)findviewbyid(r.id.btnselectcontact)).setonclicklistener( new onclicklistener() { @override public void onclick(view v) { intent intent = new intent(intent.action_get_content); intent.settype(contactscontract.commondatakinds.phone.content_item_type); startactivityforresult(intent, 1); } }); } @override protected void onactivityresult(int requestcode, int resultcode, intent data) { if (data != null) { uri uri = data.getdata(); if (uri != null) { cursor c = null; try { c = getcontentresolver().query(uri, new string[]{ contactscontract.commondatakinds.phone.number, contactscontract.commondatakinds.phone.type }, null, null, null); if (c != null && c.movetofirst()) { string number = c.getstring(0); int type = c.getint(1); showselectednumber(type, number); } } { if (c != null) { c.close(); } } } } } public void showselectednumber(int type, string number) { toast.maketext(this, type + ": " + number, toast.length_long).show(); } i did deep search beginner need understand more java. thank you
if edittext name showname use
in oncreate() method
edittext showname = (edittext) findviewbyid(r.id.xml_id_of_your_text); and in method show desired text
public void showselectednumber(int type, string number) { showname.settext(""+type + ": " + number+""); }
Comments
Post a Comment