【发布时间】:2016-10-01 10:10:14
【问题描述】:
到目前为止我的所有代码:
我将要在屏幕上显示的字符串放在 hardlist 列表中。(getDestinationCity 和 getTotalPrice) 但是我在屏幕上只看到 getTotalPrice 值。 getDestinationCity 字段为空。我想我只在屏幕上显示除键 (getDestinationCity) 之外的值 (getTotalPrice)。
我怎么知道?
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[] from = new String[]{getDestinationCity, getTotalPrice};
int[] to = 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);
for (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);
for (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);
for (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);
}
}
}
【问题讨论】:
标签: java android list listview hashmap