android - Only first EditText is being updated -
i trying update edittext(for unit price)
on basis of selected item in spinner
.
as can see in image above, every plus button
adds layout(spinner, button , 2 edittext)
.
so when first layout
added, edittext(for "unit price")
displays value selected product in spinner when add more layout, unit price
not updated in new edittext
, when change selected item of spinner
value of first edittext
updated.
this code:-
final spinner s = (spinner) newview.findviewbyid(r.id.spinner1); try { loadspinnerdata(s); } catch (ioexception e) { //todo: catch exception e.printstacktrace(); } s.setonitemselectedlistener(new adapterview.onitemselectedlistener() { @override public void onitemselected(adapterview<?> arg0, view arg1, int arg2, long arg3) { string selecteditem = s.getselecteditem().tostring(); try { loadunitprice(selecteditem); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } } private void loadunitprice(string selecteditem) throws ioexception { // database handler dbhelper db = new dbhelper(getapplicationcontext()); // spinner drop down elements string price = db.getunitprice(selecteditem); system.out.println(price); edittext unitprice = (edittext) findviewbyid(r.id.editprice); unitprice.settext(price); }
finally solved problem using this:-
s = (spinner) newview.findviewbyid(r.id.spinner1); //newview missing earlier in line below unitprice = (edittext) newview.findviewbyid(r.id.editprice); try { loadspinnerdata(s); s.setonitemselectedlistener(new adapterview.onitemselectedlistener() { @override public void onitemselected(adapterview<?> arg0, view arg1, int arg2, long arg3) { string selecteditem = s.getselecteditem().tostring(); try { loadunitprice(selecteditem, unitprice); } catch (ioexception e) { // todo auto-generated catch block e.printstacktrace(); } } @override public void onnothingselected(adapterview<?> arg0) { // todo auto-generated method stub } }); } catch (ioexception e) { //todo: catch exception e.printstacktrace(); }
loadunitprice()
:-
private void loadunitprice(string selecteditem, edittext unitprice) throws ioexception { dbhelper db = new dbhelper(getapplicationcontext()); string price = db.getunitprice(selecteditem); system.out.println(price); unitprice.settext(price); }
Comments
Post a Comment