android - custom adapter with ArrayList<HashMap<String, List<String>>> -
its complicated question, hope can me.
i want make custom adapter can handle
array list mentioned in title
currently doing this, not going getview(...) method.
public class eventsadapter extends baseadapter{ arraylist<hashmap<string, list<string>>> eventlist; private context context; private int resource; private static final string tag_title = "e_title"; public eventsadapter(context context, int resid,arraylist<hashmap<string, list<string>>> eventlist) { this.context = context; this.resource = resid; this.eventlist = eventlist; log.v("chk", "1"); } @override public view getview(int position, view convertview, viewgroup parent) { view event = convertview; textview title, desc, date, time, venue; hashmap<string, list<string>> hm = eventlist.get(position); list<string> items = hm.get(tag_title); typeface font = typeface.createfromasset(context.getassets(), "ubahn.ttf"); if( event == null ) { layoutinflater inflater = ((activity) context).getlayoutinflater(); event = inflater.inflate( resource , parent, true ); event.settag(items.get(position)); } title = (textview) event.findviewbyid( r.id.etitle); desc = (textview) event.findviewbyid( r.id.edesc ); date = (textview)event.findviewbyid(r.id.edate); time = (textview)event.findviewbyid(r.id.etiming); venue = (textview)event.findviewbyid(r.id.elocation); title.settypeface(font); system.out.print(items.get(0).tostring()); title.settext(items.get(0).tostring()); desc.settext(items.get(1).tostring()); date.settext(items.get(2).tostring()); time.settext(items.get(3).tostring()); venue.settext(items.get(4).tostring()); return event; } @override public int getcount() { // todo auto-generated method stub return 5; } @override public object getitem(int position) { // todo auto-generated method stub return eventlist.get(position).get(position).get(position); } @override public long getitemid(int position) { // todo auto-generated method stub return position; }
}
any appreciated.
here how filling data in array list
(int = 0; < products.length(); i++) { jsonobject c = products.getjsonobject(i); // storing each json item in variable string title = c.getstring(tag_title); string description = c.getstring(tag_desc); string date = c.getstring(tag_date); string time = c.getstring(tag_time); string venue = c.getstring(tag_venue); // creating new hashmap hashmap<string, list<string>> map = new hashmap<string, list<string>>(); list<string> el = new arraylist<string>(); el.add(title); el.add(description); el.add(date); el.add(time); el.add(venue); // adding each child node hashmap key => value map.put(tag_title, el); // map.put(tag_desc, description); //muap.put(tag_date, date); // adding hashlist arraylist eventlist.add(map); }
and here setting adapter
eventsadapter adapter = new eventsadapter(getactivity(), r.layout.events_list_item, eventlist); lv.setadapter( adapter);
i think useful consider when filling list.
a design pattern create data empty hashmap, establish adapter map, declare listview( or whatever ) , assign adapter empty data set. later, fill hashmap, , adapter.notifydatasetchanged
i declare these feilds:
//array of places filtered keyword list<place> places = new arraylist<place>( ); //spinner of places filtered keyword spinner placesspinner; //adapter spinner private placesspinneradapter placesspinneradapter;
in oncreate:
//this spinner, same difference placesspinner = (spinner)findviewbyid( r.id.placesspinner ); placesspinneradapter = new placesspinneradapter( this, android.r.layout.simple_spinner_dropdown_item, places ); placesspinner.setadapter( placesspinneradapter );
and somewhere in onpostexecute method of asynctask have no interest in
places.clear( ); places.addall( result.results ); placesspinneradapter.notifydatasetchanged( ); placesspinner.performclick( );
and lastly, here's difference see: adapters lists, i've never had time passing them hashmaps... map.keyset() or map.values(); hand data on adapter; know standard pattern described not work if data set hashmaps
gl hf
Comments
Post a Comment