android - keeps listview data between activities -


in android application have 2 activities(act1,act2).in act1 have gridview , data , when click 1 item start act2.in act2 have multi column listview , data , when press button data can add list.the problem when act1 , select item gridview , act2 again starts , listview becomes empty(because listview adapter in act2 oncreate method).but need previous data in list.if there idea save or keep listview data between activities.or common method or class can used insert items listview.

act1(menuactivity)

gridview.setonitemclicklistener(new onitemclicklistener() {         public void onitemclick(adapterview<?> parent, view v,                 int position, long id) {                // show message box particular name             //toast.maketext(getapplicationcontext(),((textview) v.findviewbyid(r.id.vegname)).gettext(), toast.length_short).show();              textview name=(textview) v.findviewbyid(r.id.vegname);             textview price=(textview) v.findviewbyid(r.id.vegprice);                intent = new intent(menuactivity.this, addorderactivity.class);              i.putextra("name", name.gettext().tostring());              i.putextra("price", price.gettext().tostring());               startactivity(i);           }     }); 

act2(addorderactivity)

public class addorderactivity extends activity implements view.onclicklistener   { private listview list; private arraylist<hashmap<string, string>> mylist; private hashmap<string, string> map; simpleadapter mschedule;  @override protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); setcontentview(r.layout.activityaddorder);    button btnadditem = (button) findviewbyid(r.id.btnadditem); btnadditem.setonclicklistener(this); list = (listview) findviewbyid(r.id.listorders); mylist = new arraylist<hashmap<string, string>>(); // used show heading of listview map = new hashmap<string, string>(); map.put("txtitem", "item"); map.put("txtquantity", "quantity"); map.put("txttotal", "total"); mylist.add(map); mschedule = new simpleadapter(addorderactivity.this, mylist, r.layout.listview_row, new string[] { "txtitem", "txtquantity", "txttotal" }, new int[] { r.id.txtitem, r.id.txtquantity, r.id.txttotal }); list.setadapter(mschedule);  }  @override //i want add new row on button click public void onclick(view v) {  map.put("txtitem", "1");     map.put("txtquantity", "2");     map.put("txttotal", "2");     mylist.add(map);                   mschedule.notifydatasetchanged(); } }    

i suggest use database , link list view that. way wouldn't lose data throughout application.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -