java - Update Value For TextView using EditText -
i trying sent text in edittext 1 activity through intent activity. text used update textview in second activity. edittext activity invoked using startactivityforresult(). have following code.
protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.explicitly_loaded_activity); // reference edittext field medittext = (edittext) findviewbyid(r.id.edittext); // declare , setup "enter" button button enterbutton = (button) findviewbyid(r.id.enter_button); enterbutton.setonclicklistener(new onclicklistener() { // call enterclicked() when pressed @override public void onclick(view v) { enterclicked(); } }); } // sets result send calling activity , finishes private void enterclicked() { log.i(tag,"entered enterclicked()"); // todo - save user provided input edittext field medittext = (edittext) findviewbyid(r.id.edittext); charsequence userinput = medittext.gettext(); // todo - create new intent , save input edittext field intent returnintent = new intent(explicitlyloadedactivity.this, activityloaderactivity.class); returnintent.putextra("returninput", userinput); // todo - set activity's result result code result_ok setresult(result_ok); // todo - finish activity finish(); }
this sent following code.
@override protected void onactivityresult(int requestcode, int resultcode, intent data) { log.i(tag, "entered onactivityresult()"); // todo - process result if method received both // result_ok result code , recognized request code // if so, update textview showing user-entered text. if(resultcode == result_ok && requestcode == get_text_request_code) { musertextview.settext(data.getcharsequenceextra("returninput")); } }
where musertextview textview want update. thanks.
you did not use intent created in enterclicked()
change
setresult(result_ok);
to
setresult(result_ok, returnintent);
and should work!
you can refer this link.
Comments
Post a Comment