java - How to send an ArrayList<String> to Another Activity and display there? -
how send arraylist activity , display there ? want data activity , send activity , there printed. able pass single string not array of strings
code on java file,
main activity:
edittext et1 , et2 , et3 , et4 ; public final static string message_key = "com.example.prabhav.myapplication.message"; arraylist<string> ar , tr = new arraylist<string>(); @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_full_on); } public void sm (view v) { et1= (edittext) findviewbyid(r.id.name); string msg1 = et1.gettext().tostring(); et2= (edittext) findviewbyid(r.id.dob); string msg2 = et2.gettext().tostring(); et3= (edittext) findviewbyid(r.id.emailinput); string msg3 = et3.gettext().tostring(); et4= (edittext) findviewbyid(r.id.clgi); string msg4 = et4.gettext().tostring(); ar.add(msg1); ar.add(msg2); ar.add(msg3); ar.add(msg4); tr=ar; intent intent = new intent(this,secact.class); intent.putextra("myarray",tr); startactivity(intent); }
another activity:
spinner s; public final static string message_key = "com.example.prabhav.myapplication.message"; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); intent intent= getintent(); arraylist<string> ls = (arraylist<string>) getintent().getserializableextra("myarray"); arrayadapter<string> adptr=new arrayadapter<string>(this,android.r.layout.simple_list_item_1,ls); s= (spinner) findviewbyid(r.id.sp); s.setadapter(adptr); // setcontentview(r.layout.sec_lay); }
once try follows
mainactivity
intent = new intent(this,secact.class); i.putstringarraylistextra("myarray", tr); startactivity(i);
2nd activity
arraylist<string> list=(arraylist<string>)getintent().getstringarraylistextra("myarray"); //use list wish
hope helps you.
Comments
Post a Comment