java - Android: Add TextView from one activty, to ListView in another activity through a button click -


i have textview in first activity , cannot pass content listview in second. trying take food name , add menu. below receiving activity. can tell me how fix this? many in advance

fooditemactivity.java

public class fooditemactivity extends activity {  private textview foodheader; private textview foodprice;    @override   public void oncreate(bundle bundle) {     super.oncreate(bundle);     setcontentview(r.layout.food_layout_screen);      // connect menuheader menulistheadertextview header, receives intent mainactivity below     foodheader = (textview) findviewbyid(r.id.fooditemheader);     intent = getintent();     string menuitem = i.getstringextra("childitem");     foodheader.settext(menuitem);      addtoorderbtn();     vieworderbtn();    }      // add order button     public void addtoorderbtn(){          button addtoorder_btn= (button) findviewbyid(r.id.btn_addtoorder);         addtoorder_btn.setonclicklistener(new onclicklistener(){              @override             public void onclick(view arg0){                  foodheader = (textview)findviewbyid(r.id.fooditemheader);                 //foodprice = (textview)findviewbyid(r.id.fooditemprice);                  string sendheader = foodheader.gettext().tostring();                 //string sendprice = foodprice.gettext().tostring();                    intent myintent = new intent(fooditemactivity.this, orderactivity.class);                  myintent.putextra("sendheader", sendheader);                  //myintent.putextra("sendprice", sendprice);                  startactivity(myintent);             }         });     }      // view order button     public void vieworderbtn(){          button vieworder_btn= (button) findviewbyid(r.id.btn_vieworder);         vieworder_btn.setonclicklistener(new onclicklistener(){              @override             public void onclick(view arg0){                   intent myintent = new intent(fooditemactivity.this, orderactivity.class);                  startactivity(myintent);             }          });                  }        

orderactivity.java

public class orderactivity extends listactivity {  public arraylist<string> orderlist = new arraylist<string>(); private string[] list; private arrayadapter<string> adapter; private listview lv; private string listitem;  @override   public void oncreate(bundle bundle) {     super.oncreate(bundle);     setcontentview(r.layout.order_screen);      intent = new intent();     listitem = i.getstringextra("sendheader");     // adds received sata arraylist orderlist     orderlist.add(listitem);       // assign lv order_screen's listview component order_list     lv = (listview) findviewbyid(r.id.order_list);      // convert arraylist orderlist array     list = (string[]) orderlist.toarray();      // assign adapter "this" context, layout page order_list_item, , info obtained in list     adapter = new arrayadapter<string>(this, r.layout.order_list_item, list); //r.id.order_food_name);     // set data behing lv adapter     adapter.notifydatasetchanged();     lv.setadapter(adapter);        } 

the problem arraylist declaration gets call each time when u pass intent initialize again , clear last store values don't stored values best way declare arraylist in other class , add received values arraylist , pass adapter.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -