2012-04-26 81 views

回答

0

你的問題不是很清楚。你需要先解析json。您可以將解析的數據放入BundleArrayList。不喜歡下面的內容:

String response = getResponseFromGoogleMaps(); //this function will fetch the response. write it in your way 
ArrayList<Bundle> list = new ArrayList<Bundle>(); 
try { 
     JSONObject json = new JSONObject(response); 
     JSONArray routes = json.getJSONArray("route"); 
     JSONArray legs = routes.getJSONArray(0); 
     JSONArray steps = legs.getJSONArray(0); 
     for(int i=0;i<steps.length();i++) { 
      JSONObject singleStep = steps.getJSONObject(i); 
      JSONObject duration = singleStep.getJSONObject("duration"); 
      Bundle dur = new Bundle(); 
      dur.putString("text", duration.getString("text")); 
      dur.putString("value", duration.getString("value")); 
      JSONObject distance = singleStep.getJSONObject("distance"); 
      Bundle dis = new Bundle(); 
      dis.putString("text", distance.getString("text")); 
      dis.putString("value", distance.getString("value")); 
      Bundle data = new Bundle(); 
      data.putBundle("duration", dur); 
      data.putBundle("distance", dis); 
      list.add(data); 
     } 
} catch (JSONException e1) { 
     // TODO Auto-generated catch block 
     e1.printStackTrace(); 
} 

然後創建它處理ArrayList<Bundle>自己的列表適配器(應該從BaseAdapter延伸)。你完成了!

+0

在這種情況下,就像ListAdapter一樣? – user1265628 2012-04-27 17:09:29

+0

對不起?我沒有得到你的問題! – jtanveer 2012-04-28 09:01:30