java - HashMap in ArrayList viewing on Listview Android -
all code far:
i putting string want show on screen in list of hardlist.(getdestinationcity , gettotalprice) see gettotalprice values on screen. getdestinationcity field empty. guess show values (gettotalprice) on screen except keys (getdestinationcity).
how can figure out?
public class mainactivity extends appcompatactivity { list<hashmap<string, string>> hardlist = new arraylist<hashmap<string, string>>(); string gettotalprice = null; string getdestinationcity = null; listview lv; listadapter listadapter; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); lv= (listview)findviewbyid(r.id.listview1); deserilaze(); string[] = new string[]{getdestinationcity, gettotalprice}; int[] = new int[]{r.id.name, r.id.price}; listadapter = new simpleadapter(this, hardlist, r.layout.list_item, from, to); lv.setadapter(listadapter); } public void deserilaze(){ gson gson = new gson(); airjson airjson = gson.fromjson(airfulljson, airjson.class); (itinerary itini : airjson.getresult().getitineraries()) { // system.out.println("\n"); string getselectionid = itini.getselectionid(); gettotalprice = itini.getpriceinfo().getpricebreakdown().gettotalprice().tostring(); string getcurrency = itini.getpriceinfo().getcurrency(); // system.out.println("itinerary: " + "\n" + getselectionid + "\n" + gettotalprice + "\t" + getcurrency); (trip tripin : itini.gettrips()) { getdestinationcity = tripin.getdestinationcity(); string getorigincity = tripin.getorigincity(); string getvalidatingcarrier = tripin.getvalidatingcarrier(); string getdeparturetime = tripin.getdeparturetime(); string getarrivaltime = tripin.getarrivaltime(); // system.out.println("trip: " + "\n" + getdestinationcity + "\n" + getorigincity + "\n" + getvalidatingcarrier + "\n" + // getdeparturetime + "\n" + getarrivaltime); (segment segmenti : tripin.getsegments()){ string getsegmentorigin = segmenti.getdeparturetime(); string getsegmentdestination = segmenti.getarrivaltime(); // system.out.println("segment: " + "\n" + getsegmentorigin + "\n" + getsegmentdestination); } } hashmap<string, string> list = new hashmap<string, string>(); list.put(getdestinationcity, gettotalprice); hardlist.add(list); } } }
i think should this:
//these names of columns string[] = new string[]{"destinationcity", "totalprice"}; ... //you associate key destinationcity value getdestinationcity list.put("destinationcity", getdestinationcity); //you associate key totalprice value gettotalprice list.put("totalprice", gettotalprice);
so have list of maps, each map having 2 entries (so having 2 key , associated values).
also, read meaning of simpleadapter constructor parameters:
constructor
@param context context view associated simpleadapter running
@param data list of maps. each entry in list corresponds 1 row in list. maps contain data each row, and should include entries specified in "from"
@param resource resource identifier of view layout defines views list item. layout file should include @ least named views defined in "to"
@param from list of column names added map associated each item.
@param to views should display column in "from" parameter. these should textviews. first n views in list given values of first n columns in parameter.