java - Android Eclipse ListView -
i have custom adapter & listview & i'm trying add items dynamically, not dynamically each item hard coded, need items added using loop or sort.
here's main function:
arrivals arrivals_data[] = new arrivals[] { new arrivals(getresources().getidentifier( flightinfoarray[1][2].tolowercase(), "drawable", getpackagename()), "time:" + flightinfoarray[1][1] + " | flight: " + "" + flightinfoarray[1][2].touppercase() + "" + flightinfoarray[1][3] + " | from:" + flightinfoarray[1][5] + " | via:" + flightinfoarray[1][6] + " | remarks:" + flightinfoarray[1][7] + " | eta:" + flightinfoarray[1][8]), }; arrivalsadapter adapter = new arrivalsadapter(this, r.layout.listview_arrivals_item_row, arrivals_data); listview1 = (listview) findviewbyid(r.id.listview1); listview1.setadapter(adapter); listview1.setlongclickable(true); registerforcontextmenu(listview1);
so example:
arrivals arrivals_data[] = new arrivals[] { (int = 0; < flightinforarray.length; i++) { new arrivals(getresources().getidentifier( flightinfoarray[i][2].tolowercase(), "drawable", getpackagename()), "time:" + flightinfoarray[i][1] + " | flight: " + "" + flightinfoarray[i][2].touppercase() + "" + flightinfoarray[i][3] + " | from:" + flightinfoarray[i][5] + " | via:" + flightinfoarray[i][6] + " | remarks:" + flightinfoarray[i][7] + " | eta:" + flightinfoarray[i][8]), } };
that of course can't done so, ideas?
thank in advance!
you want create arrivals
array dynamically. can this:
arraylist<arrivals> arrivals = new arraylist<arrivals>(); (int = 0; < flightinfoarray.length; i++) { arrivals new_arrival = new arrivals(getresources().getidentifier( flightinfoarray[i][2].tolowercase(), "drawable", getpackagename()), "time:" + flightinfoarray[i][1] + " | flight: " + "" + flightinfoarray[i][2].touppercase() + "" ....); arrivals.add(new_arrival); } //now convert arraylist array arrivals[] arrivals_data = new arrivals[arrivals.size()]; arrivals_data = arrivals.toarray(arrivals_data);
now can supply arrivals_data
array array adapter usual.
arrivalsadapter adapter = new arrivalsadapter(this, r.layout.listview_arrivals_item_row, arrivals_data);
Comments
Post a Comment