eclipse - transfer data of 5 activity pages 26 edit text fields and calculate in last android activity -
my problem related android application far able create 5 different activities variables , onclick button pass on next activity...
public class abc extends activity{ button one2five; edittext edta, edtb, edtc, edtd, edte, edtf; string ta, tb, tc, td, te, tf; @override protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); setcontentview(r.layout.abc); one2five = (button) findviewbyid(r.id.btp1); edta = (edittext) findviewbyid(r.id.eta); ta = edta.gettext().tostring(); edtb = (edittext) findviewbyid(r.id.etb); tb = edtb.gettext().tostring(); edtc = (edittext) findviewbyid(r.id.etc); tc = edtc.gettext().tostring(); edtd = (edittext) findviewbyid(r.id.etd); td = edtd.gettext().tostring(); edte = (edittext) findviewbyid(r.id.ete); te = edte.gettext().tostring(); edtf = (edittext) findviewbyid(r.id.etf); tf = edtf.gettext().tostring(); one2five.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub intent openg2j = new intent("com.sport.sport.g2j"); startactivity(openg2j); } }); } }
now base created 4 more pages , total 26 different edittext fields.
my objective is:- edit text in 1 calculate page. perform claculation , post result in on 1 page.
problem:- user text all decimal numbers user prompt if field left blank highlighted field. if user press previous activity should have entered values.
can 1 me solve issue.. monika
with various methodology can handle
1- either define field @ application level keep alive field alive untill , unless application alive pros: once defined use through out application cons: once app close data lost.
2- pass value in intent handle in next activity , combine field of previous , current activity , pass on next activity pros: use fields in , forth activity cons: once app close data lost. 3- save field in shared preferences , use time either app alive or not pros: data saved once committed.
4- can use arraylist , add data in every current next activity context switching scenario want use
and if want have data in previous activity can override method onbackpressed , perform functionality accordingly
sample code using method 2
modified code in question
public class abc extends activity{ button one2five; edittext edta, edtb, edtc, edtd, edte, edtf; string ta, tb, tc, td, te, tf; @override protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); setcontentview(r.layout.abc); one2five = (button) findviewbyid(r.id.btp1); edta = (edittext) findviewbyid(r.id.eta); ta = edta.gettext().tostring(); edtb = (edittext) findviewbyid(r.id.etb); tb = edtb.gettext().tostring(); edtc = (edittext) findviewbyid(r.id.etc); tc = edtc.gettext().tostring(); edtd = (edittext) findviewbyid(r.id.etd); td = edtd.gettext().tostring(); edte = (edittext) findviewbyid(r.id.ete); te = edte.gettext().tostring(); edtf = (edittext) findviewbyid(r.id.etf); tf = edtf.gettext().tostring(); one2five.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub intent openg2j = new intent("com.sport.sport.g2j"); openg2j .putextra("field1data", ta); openg2j .putextra("field2data", tb); openg2j .putextra("field3data", tc); openg2j .putextra("field4data", td); openg2j .putextra("field5data", te); startactivity(openg2j); } }); }
this how can send data current class next class }
edited :
in 2ndactivity can data ,
string field5data = getintent().getstringextra("field5data") ;
Comments
Post a Comment