我的问题是,我有JSON中的数据,我使用AsyncHttpClient Lib得到它,并填充ListView ...但问题是,我如何设置来自Url的图像,这个Url是在Json数据中。
代码:
AsyncHttpClient client = new AsyncHttpClient();
RequestParams params = new RequestParams();
params.put("q", "London");
params.put("format","json");
params.put("num_of_days","5");
params.put("key", "****");
client.get("http://api.worldweatheronline.com/free/v1/weather.ashx", params,
new JsonHttpResponseHandler() {
@Override
public void onSuccess(JSONObject response) {
//showProgress(false);
try {
JSONArray forecast = response.getJSONObject("data").getJSONArray("weather");
for(int i=0;i < forecast.length();i++){
HashMap<String, Object> map = new HashMap<String, Object>();
JSONObject e = forecast.getJSONObject(i);
JSONArray urlJsonArray = e.getJSONArray("weatherIconUrl");
JSONObject e1 = urlJsonArray.getJSONObject(0);
map.put("id", String.valueOf(i));
map.put("date", "Data: " + e.getString("date"));
map.put("image",e1.getString("value"));
map.put("tempMinC", "Min:" + e.getString("tempMinC"));
map.put("tempMaxC", "Max:" + e.getString("tempMaxC"));
oslist.add(map);
}
list=(ListView)findViewById(R.id.list);
ListAdapter adapter = new SimpleAdapter(Consulting_Test.this, oslist,
R.layout.list_v,
new String[] { "date" ,"image","tempMinC", "tempMaxC" }, new int[] {
R.id.nome,R.id.weatherImage,R.id.esito, R.id.crediti});
list.setAdapter(adapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
//Toast.makeText(Consulting_Test.this, "You Clicked at "+oslist.get(+position).get("name"), Toast.LENGTH_SHORT).show();
}
});
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
在这个剪辑中,我只放了网址,但是我想要一个Image..sorry,因为我的英文不好
答案 0 :(得分:0)
我用LazyAdapter解决了这个问题。