android - Edittext.settext() Don't show text in onActivityResult() -
i trying add text in edittext
on activityresult
, doesn't work. here have done:
private view getnumber() { layoutinflater inflater = layoutinflater.from(getbasecontext()); viewnumber = inflater.inflate(r.layout.stepper_layout, null, false); number_edittext = (appcompatedittext) viewnumber.findviewbyid(r.id.pic_edittext_number); relativelayout numberpickerlayout = (relativelayout) viewnumber.findviewbyid(r.id.numberpickerlayout); relativelayout pic_number = (relativelayout) viewnumber.findviewbyid(r.id.pic_number); button numbernext = (button) viewnumber.findviewbyid(r.id.numbernext); numberpickerlayout.setvisibility(view.visible); pic_number.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { intent contactpickerintent = new intent(intent.action_pick, contactscontract.commondatakinds.phone.content_uri); startactivityforresult(contactpickerintent, contact_picker_result); } }); numbernext.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { num = number_edittext.gettext().tostring(); if (textutils.isempty(num)) { verticalstepperform.setactivestepasuncompleted("please enter or select number"); } else { checknumber(num); } } }); return viewnumber; } @override protected void onactivityresult(int requestcode, int resultcode, intent data) { if (resultcode == result_ok && requestcode == contact_picker_result) { cursor cursor = null; uri uri = data.getdata(); //query content uri cursor = getcontentresolver().query(uri, null, null, null, null); cursor.movetofirst(); int phoneindex = cursor.getcolumnindex(contactscontract.commondatakinds.phone.number); phoneno = cursor.getstring(phoneindex); number_edittext.settext(phoneno); } }
try one..
public class mainactivity extends appcompatactivity {
private static final int contact_picker_result = 100; // create variable textview mtextview; button pickcontactbtn; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_test); // find text view id here mtextview = (textview) findviewbyid(r.id.textview1); // work here mtextview.settext("hello world!"); pickcontactbtn= (button) findviewbyid(r.id.pickcontactbtn); pickcontactbtn.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { intent contactpickerintent = new intent(intent.action_pick, contactscontract.commondatakinds.phone.content_uri); startactivityforresult(contactpickerintent, contact_picker_result); } }); } @override protected void onactivityresult(int requestcode, int resultcode, intent data) { if (resultcode == result_ok && requestcode == contact_picker_result) { cursor cursor = null; uri uri = data.getdata(); //query content uri cursor = getcontentresolver().query(uri, null, null, null, null); cursor.movetofirst(); int phoneindex = cursor.getcolumnindex(contactscontract.commondatakinds.phone.number); string phoneno = cursor.getstring(phoneindex); mtextview.settext(phoneno); } }
}
xml
<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".mainactivity"> <textview android:id="@+id/textview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="hello_world" android:textsize="36sp" android:textcolor="@android:color/holo_blue_dark" android:textstyle="bold" android:layout_marginleft="12dp" android:layout_margintop="12dp" /> <button android:id="@+id/pickcontactbtn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/textview1" android:layout_alignstart="@+id/textview1" android:layout_below="@+id/textview1" android:layout_marginleft="18dp" android:layout_marginstart="18dp" android:layout_margintop="28dp" android:text="pick contact" /> </relativelayout>
Comments
Post a Comment