android - Get the position in a ListView of a Spinner and get its selected value -
i implemented arrayadapter
listview
:
public class calcamrlistadapter extends arrayadapter<amrstatelistentry> implements onitemselectedlistener { public calcamrlistadapter(context context, list<amrstatelistentry> entries) { super(context, r.layout.activity_calc_amr_fragment_row, entries); } @override public view getview(int position, view convertview, viewgroup parent) { amrstatelistentry entry = this.getitem(position); viewholder viewholder = null; layoutinflater inflater = null; if(convertview == null) { viewholder = new viewholder(); inflater = layoutinflater.from(this.getcontext()); convertview = inflater.inflate(r.layout.activity_calc_amr_fragment_row, parent, false); viewholder.spinneractivity = (spinner) convertview.findviewbyid(r.id.calc_amr_row_spinner_activity); viewholder.spinnerhours = (spinner) convertview.findviewbyid(r.id.calc_amr_row_spinner_hours); viewholder.textviewpal = (textview) convertview.findviewbyid(r.id.calc_amr_row_textview_pal); viewholder.imagebuttondelete = (imagebutton) convertview.findviewbyid(r.id.calc_amr_row_button_delete); convertview.settag(viewholder); } else { viewholder = (viewholder) convertview.gettag(); } string pal = null; switch (entry.getactivity()) { case 1: pal = "" + 0.95; break; case 2: pal = "" + 1.2; break; case 3: pal = "" + 1.5; break; case 4: pal = "" + 1.7; break; case 5: pal = "" + 1.9; break; case 6: pal = "" + 2.4; break; default: pal = ""; break; } viewholder.spinneractivity.setselection(entry.getactivity()); viewholder.spinneractivity.setonitemselectedlistener(this); viewholder.spinnerhours.setselection(entry.gethour()); viewholder.spinnerhours.setonitemselectedlistener(this); viewholder.textviewpal.settext(pal); viewholder.imagebuttondelete.setimageresource(r.drawable.ic_remove_row); return convertview; } @override public void onitemselected(adapterview<?> parent, view view, int position, long id) { } @override public void onnothingselected(adapterview<?> parent) {} private static class viewholder { spinner spinneractivity = null; spinner spinnerhours = null; textview textviewpal = null; imagebutton imagebuttondelete = null; } }
as can see each item of listview
contains 2 spinner
. in onitemselected
method need position of row in listview
spinner
used select value , need differ between 2 spinners in 1 row. data model amrstatelistentry
. need set selected values of spinners inside amrstatelistentry
.
how can that?
viewholder.spinnerhours.setonitemselectedlistener(new onitemselectedlistener() { @override public void onitemselected(adapterview<?> parent, view view, int positioninspinner, long id) { // todo auto-generated method stub } @override public void onnothingselected(adapterview<?> parent) { // todo auto-generated method stub } });
create instead. set public view getview(final int position, view convertview, viewgroup parent)
position final
. can use final int position
inside onitemselected
.
and same other spinner
Comments
Post a Comment