for (int i = 0; i < productsofitems.length(); i++)
{
count=productsofitems.length();
System.out.println("count is"+productsofitems.length());
JSONObject c = productsofitems.getJSONObject(i);
// Storing each json item in variable
//String id = c.getString(TAG_CATEGORYID);
String procid = c.getString(TAG_PRODUCTID);
System.out.println(procid);
String id = c.getString(TAG_CATEGORYID);
System.out.println(id);
String productname = c.getString(TAG_PRODUCTNAME);
System.out.println(productname);
//String title = c.getString(TAG_TITLE);
//System.out.println(title);
//String smalldesc = c.getString(TAG_SMALLDESCRIPTION);
//System.out.println(smalldesc);
//String originalprice = c.getString(TAG_ORIGINALPRICE);
//System.out.println(originalprice);
String salesprice = c.getString(TAG_SALEPRICE);
System.out.println(salesprice);
String smallimage = c.getString(TAG_SMALLIMAGE);
System.out.println(smallimage);
String stocks = c.getString(TAG_STOCK);
System.out.println(stocks);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(TAG_PRODUCTID, procid);
map.put(TAG_CATEGORYID, id);
map.put(TAG_PRODUCTNAME, productname);
//map.put(TAG_TITLE, title);
//map.put(TAG_SMALLDESCRIPTION, smalldesc);
//map.put(TAG_ORIGINALPRICE, originalprice);
map.put(TAG_SALEPRICE, salesprice);
map.put(TAG_SMALLIMAGE, smallimage);
map.put(TAG_STOCK, stocks);
// adding HashList to ArrayList
productListofitems.add(map);
System.out.println("inside"+count);
}
}
else {
Log.d("ProductListofitems: ", "null");
// no products found
// Launch Add New product Activity
//Intent i = new Intent(getApplicationContext(),
//NewProductActivity.class);
// Closing all previous activities
//i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// startActivity(i);
}
}
catch (JSONException e) {
e.printStackTrace();
}
return null;
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url) {
// dismiss the dialog after getting all category
pDialog.dismiss();
// updating UI from Background Thread
runOnUiThread(new Runnable() {
public void run() {
/**
* Updating parsed JSON data into ListView
* */
int[] images = {
R.drawable.a, R.drawable.banner2,
R.drawable.banner4, R.drawable.banner1
};
ListAdapter adapter = new SimpleAdapter(
ProductListofitems.this, productListofitems,
R.layout.productlistofitems, new String[] {
TAG_PRODUCTID,TAG_CATEGORYID,TAG_PRODUCTNAME,TAG_SALEPRICE,TAG_STOCK},
new int[] {R.id.product_id,R.id.catgory_id,R.id.title,R.id.saleprice,R.id.stock});
// updating listview
setListAdapter(adapter);
System.out.println("post execute");
textview.setText(+count+" results for "+"'"+cat_title+"'");
}
});
}
如何從URL下載圖片。我得到的URL作爲響應,以及如何下載和設置在listview的imageview。如何從URL下載圖像並在imageview中設置?我已經附上了這個代碼。如何從網站下載圖片並設置在圖片查看器
如果你需要更多的選擇,而不僅僅是下載圖像或者你在幾個地方使用它。我建議使用一些第三方庫,如Universal Image Loader(https://github.com/nostra13/Android-Universal-Image-Loader)或picasso(http://square.github.io/picasso/)或volley(https ://github.com/mcxiaoke/android-volley) – 2014-11-14 14:32:58