android - Retrieve data from Spinner in the ListView -


i'm implementing custom list view has spinner, have textview , others each list item. , want selected value of spinner each row of list view. first item of spinner. can this?

i looked through many of posts here answers requires changing code completely. don't want write code on again.

here custom adapter:

public class customadapter extends arrayadapter<datamodel> {      private arraylist<datamodel> dataset;     context mcontext;      private static class viewholder {         textview txtname;         checkbox checkbox;         textview price;         spinner spinner;         datamodel data1;      }      public customadapter(arraylist<datamodel> data, context context) {         super(context, r.layout.row_item, data);         this.dataset = data;         this.mcontext = context;      }     @override     public int getcount() {         return dataset.size();     }      @override     public datamodel getitem(int position) {         return dataset.get(position);     }       @override     public view getview(int position, view convertview, @nonnull viewgroup parent) {          final viewholder viewholder;         final view result;          if (convertview == null) {             viewholder = new viewholder();             convertview = layoutinflater.from(parent.getcontext()).inflate(r.layout.row_item, parent, false);             viewholder.txtname = (textview) convertview.findviewbyid(r.id.txtname);             viewholder.checkbox = (checkbox) convertview.findviewbyid(r.id.checkbox);             viewholder.price = (textview) convertview.findviewbyid(r.id.priceid);             viewholder.spinner = (spinner) convertview.findviewbyid(r.id.spinner);              viewholder.spinner.setfocusable(false);              result=convertview;             convertview.settag(viewholder);          } else {             viewholder = (viewholder) convertview.gettag();             result=convertview;         }          final datamodel item = getitem(position);           viewholder.txtname.settext(item.name);         viewholder.checkbox.setchecked(item.checked);         viewholder.price.settext(item.price.tostring());         viewholder.spinner.setonitemselectedlistener(new adapterview.onitemselectedlistener() {             @override             public void onitemselected(adapterview<?> adapterview, view view, int i, long l) {                 item.setportion(viewholder.spinner.getselecteditem().tostring());             }              @override             public void onnothingselected(adapterview<?> adapterview) {              }         });            return result;     } } 

and data model:

public class datamodel {      public string name;     public double price;     boolean checked;     public string portion;      public void setportion(string portion) {         this.portion = portion;     }      public string getportion() {         return portion;     }      public boolean ischecked() {         return checked;     }      public void setchecked(boolean checked) {         this.checked = checked;     }      public double getprice() {         return price;     }      public string getname() {         return name;     }      public datamodel(string name, double price, boolean checked) {         this.name = name;         this.price = price;         this.checked = checked;     }      public datamodel(string name) {         this.name = name;     } } 


Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -