android - How to add selected spinner values dynamically in listview is in another activity -


how add selected spinner values dynamically in listview in activity.

when have changed spinner value in second time,and open listview activity values replaced in listview not added.

public class mainactivity extends activity implements onclicklistener {  sharedpreferences sharedprefs; string sp_selected; spinner sp; string s1; string partname; string partname1; button parts_history;  imageadapter image_adapter;  private static final string[] paths = { "select choice", "type1",         "type2", "type3", "type4" }; private static final int position = 0;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     this.requestwindowfeature(window.feature_no_title);     setcontentview(r.layout.partsrepair);      image_adapter = new imageadapter(this);      sharedprefs = getsharedpreferences("preference", mode_private);      gridview gridview = (gridview) findviewbyid(r.id.gridview1);     gridview.setadapter(new imageadapter(this));      parts_history = (button) findviewbyid(r.id.partshistory_button);     parts_history.setonclicklistener((this));      gridview.setonitemclicklistener(new onitemclicklistener() {         public void onitemclick(final adapterview<?> parent, view v,                 int position, long id) {              sharedpreferences.editor edit = sharedprefs.edit();              // partname = parent.getitematposition(position).tostring();             partname1 = image_adapter.names[position].tostring();             image_adapter.names[position].tostring();             toast.maketext(mainactivity.this, "you selected:" + partname1,                     toast.length_short).show();              // edit.putstring("selectpart", partname1);              final dialog dialog = new dialog(mainactivity.this);             dialog.requestwindowfeature(window.feature_no_title);             dialog.setcontentview(r.layout.repairtype_spinner);             dialog.setcancelable(true);              spinner sp = (spinner) dialog.findviewbyid(r.id.spinner_1);              arrayadapter<string> adapter = new arrayadapter<string>(                     mainactivity.this,                     android.r.layout.simple_spinner_item, paths);              sp.setadapter(adapter);              sp.setonitemselectedlistener(new onitemselectedlistener() {                  @override                 public void onitemselected(adapterview<?> parent,                         view view, int position, long id) {                      if (position > 0) {                         sp_selected = parent.getitematposition(position)                                 .tostring();                     }                 }                  @override                 public void onnothingselected(adapterview<?> arg0) {                     // todo auto-generated method stub                  }             });              button btnok = (button) dialog.findviewbyid(r.id.button_sms_ok);             btnok.setonclicklistener(new view.onclicklistener() {                  @override                 public void onclick(view v) {                     sharedpreferences.editor edit = sharedprefs.edit();                      if ((sp_selected != null)                             && !sp_selected.equals("select choice")) { //                         edit.putstring("selecttype", sp_selected);                          toast.maketext(getapplicationcontext(),                                 "you selected:" + sp_selected,                                 toast.length_short).show();                          toast.maketext(getapplicationcontext(),                                 "thank you!", toast.length_long).show();                          dialog.dismiss();                     } else {                          toast.maketext(mainactivity.this,                                 "plz select choice",                                 toast.length_short).show();                     }                  }             });              dialog.show();          }      }); }  public void onclick(view v) {      switch (v.getid()) {     case r.id.partshistory_button:          intent intent = new intent(mainactivity.this, listviewitems.class);         intent.putextra("part", partname1);         intent.putextra("type", sp_selected);         startactivity(intent);         finish();     } } } 

listviewitems.class:

public class listviewitems extends activity {  arraylist<string> part, type;  listview list;  public listviewitems() {     // todo auto-generated constructor stub     part = new arraylist<string>();     type = new arraylist<string>(); }  @override protected void oncreate(bundle savedinstancestate) {     // todo auto-generated method stub     super.oncreate(savedinstancestate);     setcontentview(r.layout.sms_summary);      intent = getintent();     part.add(i.getstringextra("part"));     type.add(i.getstringextra("type"));      list = (listview) findviewbyid(r.id.listview1);     arrayadapter<string> adapter = new arrayadapter<string>(             getbasecontext(), r.layout.listview, type);     list.setadapter(new customviewadapter(listviewitems.this));     adapter.notifydatasetchanged(); }  public class customviewadapter extends baseadapter {      context context;      public customviewadapter(context context) {         // todo auto-generated constructor stub         this.context = context;     }      private class viewholder {         textview text_part;         textview text_type;     }      public view getview(int position, view convertview, viewgroup parent) {         viewholder holder = null;         // log.d("hao",""+position);          layoutinflater minflater = (layoutinflater) context                 .getsystemservice(activity.layout_inflater_service);         if (convertview == null) {             convertview = minflater.inflate(r.layout.listview, null);             holder = new viewholder();             holder.text_part = (textview) convertview                     .findviewbyid(r.id.textview1);             // log.d("hao", ""+holder.text_desc);             holder.text_type = (textview) convertview                     .findviewbyid(r.id.textview2);             convertview.settag(holder);         }          else             holder = (viewholder) convertview.gettag();          holder.text_type.settext(type.get(position));         holder.text_part.settext(part.get(position));          return convertview;      }      @override     public int getcount() {         // todo auto-generated method stub         return part.size();     }      @override     public object getitem(int position) {         // todo auto-generated method stub         return position;     }      @override     public long getitemid(int position) {         // todo auto-generated method stub         return position;     }  }  } 


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -