android - How do I properly pass EditText (in 1st activity that creates a TextView in 2nd activity) to a third activity as TextView? -
i have login button when pressed sends user activity , post users name in textview. part working fine. trouble when try pass username in second activity textview on third activity textview doesn't show up. android:hint shows text know xml fine. i've tried every kind of "putextra" intent find on site. think missed something..help. i'm totally new android laugh @ newbie :)
activity 2
public class dashboardactivity extends activity { userfunctions userfunctions; button btnlogout; button scanbutton; button userinfo; button help; button receipt; textview showmsg; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); /** * dashboard screen application * */ // check login status in database userfunctions = new userfunctions(); if(userfunctions.isuserloggedin(getapplicationcontext())){ setcontentview(r.layout.dashboard); scanbutton = (button) findviewbyid(r.id.scanbutton); btnlogout = (button) findviewbyid(r.id.btnlogout); userinfo = (button) findviewbyid(r.id.userinfo); = (button) findviewbyid(r.id.help); receipt = (button)findviewbyid(r.id.receipt); showmsg = (textview)findviewbyid(r.id.showmsg); intent in = getintent(); if (in.getcharsequenceextra("usr") != null) { final textview setmsg = (textview)findviewbyid(r.id.showmsg); setmsg.settext("user: "+in.getcharsequenceextra("usr")); } btnlogout.setonclicklistener(new view.onclicklistener() { public void onclick(view arg0) { // todo auto-generated method stub userfunctions.logoutuser(getapplicationcontext()); intent login = new intent(getapplicationcontext(), loginactivity.class); login.addflags(intent.flag_activity_clear_top); startactivity(login); // closing dashboard screen finish(); } }); // link cc scanbutton.setonclicklistener(new view.onclicklistener() { public void onclick(view view) { intent = new intent(getapplicationcontext(), myscanactivity.class); startactivity(i); finish(); } }); // create customer receipt receipt.setonclicklistener(new view.onclicklistener() { public void onclick(view view) { intent intent = new intent(dashboardactivity.this, receiptactivity.class)); intent.putextra("textview",showmsg); startactivity(intent); finish(); } }); // link user info userinfo.setonclicklistener(new view.onclicklistener() { public void onclick(view view) { intent = new intent(getapplicationcontext(), userinfoactivity.class); startactivity(i); finish(); } }); // link info help.setonclicklistener(new view.onclicklistener() { public void onclick(view view) { intent = new intent(getapplicationcontext(), helpactivity.class); startactivity(i); finish(); } }); }else{ // user not logged in show login screen intent login = new intent(getapplicationcontext(), loginactivity.class); login.addflags(intent.flag_activity_clear_top); startactivity(login); // closing dashboard screen finish(); } }
}
@smulianjulian:
there mistake. re passing component textview next intent, while should passing it's text only.
you doing :
intent.putextra("textview",showmsg);
but should
bundle extras = myintent.getextras(); extras .putstring("textview",showmsg.gettext().tostring());
and in 3rd activity should value :
bundle = getintent().getextras(); bundle.getstring("textview");
and set value textview.
textview yourtv = ((textview) findviewbyid(r.id.your_textview_id)); yourtv.settext(bundle.getstring("textview"));
hope helps.
Comments
Post a Comment