java - Constructor mismatch for Custom Adapter -
i trying create first custom adapter generate listview android app. getting data api call , process , store in arraylist:-
class person{ string bioguide; string image; string lastname; string firstname; string district; string state; string party;} public static arraylist<person> persondata = new arraylist<person>();
now in onpostexecute section trying create listview , custom adapter display data follows:-
listview yourlistview = (listview) rootview.findviewbyid(r.id.state_listview); listadapter customadapter = new arrayadapter<person>(bystate.this, r.layout.bystate_itemview,persondata); yourlistview .setadapter(customadapter); } } public class listadapter extends arrayadapter<person> { public listadapter(context context, int textviewresourceid) { super(context, textviewresourceid); } public listadapter(context context, int resource, arraylist<person> items) { super(context, resource, items); } @override public view getview(int position, view convertview, viewgroup parent) { view v = convertview; if (v == null) { layoutinflater vi; vi = layoutinflater.from(getcontext()); v = vi.inflate(r.layout.bystate_itemview, null); } person p = getitem(position); if (p != null) { textview tt1 = (textview) v.findviewbyid(r.id.last_name); textview tt2 = (textview) v.findviewbyid(r.id.first_name); if (tt1 != null) { tt1.settext(p.getlastname()); } if (tt2 != null) { tt2.settext(p.getfirstname()); } } return v; } } }
i got above code following internet tutorial. thing getting error in line use customadapter first invoke constructor of custom adapter. says cannot resolve constructor. can me in understanding this. know have not defined proper constructor case please let me know changes. creating listview inside fragment , fragment class name bystate.
in second line replace
listadapter customadapter = new arrayadapter<person>(bystate.this, r.layout.bystate_itemview,persondata);
by
listadapter customadapter = new listadapter(bystate.this, r.layout.bystate_itemview, persondata);
you create own adapter class, invoke standart arrayadapter
Comments
Post a Comment