android - ArrayAdapter from ArrayList showing resource ID not value -
i attempting populate spinner arraylist.
the issue have instead of displaying values in arraylist, spinner showing full path resource id instead!
my code
@override public void cartonmoveoptions(arraylist<barcodespinner> bspinner) { spinner barcodechoice = (spinner) rootview.findviewbyid(r.id.cartonchoices); barcodechoice.setvisibility(view.visible); arrayadapter<barcodespinner> = new arrayadapter<barcodespinner>(getactivity(), android.r.layout.simple_spinner_item, bspinner); a.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item); barcodechoice.setadapter(a); }
barcodespinner contains 2 lines, , content single string each line.
can point out wrong?
this barcodespinner class
public class barcodespinner { string barcode; public string getbarcode() { return barcode; } public void setbarcode(string barcode) { barcode = barcode; } }
answer:
add
@override public string tostring() { return barcode; }
to barcodespinner
the default implementation of arrayadapter
, invoke tostring
method of object provide in dataset. easy fix override tostring
in barcodespinner
class, making return string want show
Comments
Post a Comment