java - ArrayAdapter using ArrayList but display only 1 value of an array on Spinner -
i have arraylist<string[]> lstprovinceinfo
this
{"id":"1","province_code":"hni","province_name":"hà nội"}, {"id":"2","province_code":"hcm","province_name":"tp hồ chí minh"}, {"id":"3","province_code":"dng","province_name":"Đà nẵng"}
now i'm creating arrayadapter use spinner dropdown this
arrayadapter<string[]> adapter = new arrayadapter<>(this, r.layout.custom_ddlist, lstprovinceinfo); adapter.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item);
the display result got in spinner is:
[ljava.lang.string;@3286c7b8 [ljava.lang.string;@3286c808 [ljava.lang.string;@3286c818
how can display "province_name" part in arraylist on spinner still keep follwing id, province_code? in advanced.
create customarrayadapter ....
you won;t allow pass arraylist (arraylist of string array) set actual parameter pass arrayadapter arraylist .. hence in case object of string array been passed , internally string[].tostring() called .
public class customarrayadapter extends baseadapter { private arraylist<string[]> list; private context mcontext; private int resid; public customarrayadapter(context mcontext,int resid, arraylist<string[]> list) { this.mcontext=mcontext; this.resid=resid; this.list=list; } //override getview method //override getcount method , others }
now pass arraylist customarrayadapter , set adapter list or spinner
Comments
Post a Comment