android - Get values from dynamic spinners -


i creating spinners dynamically when click add button.but dont know how values created dynamic spinners.i need values how many shirt selected, saree selected , jeans selected when click submit button

enter image description here

this code

 buttonadd = (button)findviewbyid(r.id.add);   container = (linearlayout)findviewbyid(r.id.container);   final list<string> dressarray =  new arraylist<string>();   dressarray.add("select dress");   dressarray.add("shirt");   dressarray.add("saree");   dressarray.add("jeans");    arrayadapter<string> adapter = new arrayadapter<string>(       this, android.r.layout.simple_spinner_item, dressarray);    adapter.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item);   spinner dress = (spinner) findviewbyid(r.id.dress);   dress.setadapter(adapter);     final list<string> dresscountarray =  new arraylist<string>();   dresscountarray.add("count");   dresscountarray.add("1");   dresscountarray.add("2");    dresscountarray.add("3");     arrayadapter<string> adapter1 = new arrayadapter<string>(       this, android.r.layout.simple_spinner_item, dresscountarray);    adapter.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item);   spinner dresscount = (spinner) findviewbyid(r.id.dresscount);   dresscount.setadapter(adapter1);   buttonadd.setonclicklistener(new onclicklistener(){     @override    public void onclick(view arg0) {     layoutinflater layoutinflater =        (layoutinflater) getbasecontext().getsystemservice(context.layout_inflater_service);     final view addview = layoutinflater.inflate(r.layout.row, null);       spinner dresscount = (spinner)addview.findviewbyid(r.id.dresscount);     spinner dress = (spinner)addview.findviewbyid(r.id.dress);      arrayadapter<string> adapter = new arrayadapter<string>(               pickuporder.this, android.r.layout.simple_spinner_item, dressarray);            adapter.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item);           dress.setadapter(adapter);             arrayadapter<string> adapter1 = new arrayadapter<string>(                   pickuporder.this, android.r.layout.simple_spinner_item, dresscountarray);                adapter.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item);               dresscount.setadapter(adapter1);        button buttonremove = (button)addview.findviewbyid(r.id.remove);     buttonremove.setonclicklistener(new onclicklistener(){       @override      public void onclick(view v) {       ((linearlayout)addview.getparent()).removeview(addview);      }});      container.addview(addview);    }}); 

firstly define globally

string value1; int value_position1; 

and call these methods inside oncreate after setting value in each spinner

spinner1.setonitemselectedlistener(new onitemselectedlistener() {                 @override                 public void onitemselected(adapterview<?> parent,                         view view, int position, long id) {                     value_position1 = position;                     value1 = parent.getselecteditem().tostring()                             .trim();                 }                  @override                 public void onnothingselected(adapterview<?> parent) {                 }             }); 

and when call submit button, use values of each string.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -