即時通訊新的Android,這似乎是沒有理由的過於複雜。Android的 - 從ListView ImageView中的位置圖像從JSON API調用
我有一個simpleadapter將數據添加到列表視圖與5值。其中之一是圖片的網址。我只是希望imageview將其作爲源代碼。
繼承人的JSON請求
private void makeJsonArrayRequest() {
showpDialog();
JsonArrayRequest req = new JsonArrayRequest(urlJsonArry,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
Log.d(TAG, response.toString());
try {
// Parsing json array response
// loop through each json object
jsonResponse = "";
for (int i = 0; i < response.length(); i++) {
JSONObject dealObject = (JSONObject) response.get(i);
String dealTitle = dealObject.getString("title");
int dealPrice = dealObject.getInt("price");
String brandLogo = dealObject.getString("brandlogo");
int dealVotes = dealObject.getInt("votes");
String dealRetailer = dealObject.getString("brand");
ImageView thumbnail = (ImageView) findViewById(R.id.brandlogo);
jsonResponse += "title: " + dealTitle + "\n\n";
jsonResponse += "price: " + dealPrice + "\n\n";
jsonResponse += "brandlogo: " + brandLogo + "\n\n";
jsonResponse += "votes: " + dealVotes + "\n\n\n";
jsonResponse += "retailer: " + dealRetailer + "\n\n\n\n\n";
HashMap<String, String> map = new HashMap<String, String>();
map.put("1", dealTitle);
map.put("2", "€" + dealPrice+".00");
map.put("3", brandLogo);
map.put("4", dealVotes+"");
map.put("5", dealRetailer);
oslist.add(map);
list=(ListView)findViewById(R.id.listView);
ListAdapter adapter = new SimpleAdapter(MainActivity.this, oslist,
R.layout.list_item_1,
new String[] { "1","2","3","4","5"}, new int[] {
R.id.title,
R.id.price,
R.id.brandlogo,
R.id.votes,
R.id.retailer
});
list.setAdapter(adapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Toast.makeText(MainActivity.this, "You Clicked at "+oslist.get(+position).get("1"), Toast.LENGTH_SHORT).show();
}
});
}
} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(),
"Error: " + e.getMessage(),
Toast.LENGTH_LONG).show();
}
hidepDialog();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
Toast.makeText(getApplicationContext(),
error.getMessage(), Toast.LENGTH_SHORT).show();
hidepDialog();
}
});
// Adding request to request queue
VolleyAdapter.getInstance().addToRequestQueue(req);
}
有沒有簡單的方法來簡單地添加「brandlogo」到「縮略圖」?
謝謝
這可以放在list.setAdapter(適配器)之前;或我在哪裏添加它?謝謝 – ChrisM
最好的地方可能會在你的適配器的getView()。看到[這個例子](http://stackoverflow.com/questions/23142734/how-to-use-networkimageview-in-a-listview) – SoroushA
我必須做錯了什麼,因爲在VolleyAdapter中沒有getView。我也使用SimpleAdapter。 – ChrisM