I want to display images on GridView populate it from JSON URL.
Here is my code, I have ArrayList now want to display these image on GridView from URL.
ArrayList<String> ImgArray = new ArrayList<String>();
private class DownloadFilesTask extends AsyncTask<Void, Void, Void> {
private ProgressDialog pDialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
// before making http calls
Log.e("JSON", "Pre execute");
ImgArray.clear();
newArray.clear();
galleryArray.clear();
pDialog = new ProgressDialog(PhotosDetail.this);
pDialog.setMessage("Getting Data ...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
@Override
protected Void doInBackground(Void... arg0) {
JSONParser jsonParser = new JSONParser();
JSONArray json = jsonParser.getJSONFromUrl(url, category, galleryid);
if (json != null) {
try {
for (int i = 0; i < json.length(); i++) {
JSONObject arr = json.getJSONObject(i);
newArray.add(arr.getString(TAG_NAME));
galleryArray.add(arr.getString(TAG_GALLERY));
String image = arr.getString(TAG_IMAGE);
image = "http://fromwebsite.net/media" + image;
ImgArray.add(image);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return null;
}
@Override
protected void onPostExecute(Void result) {
pDialog.dismiss();
//What I want here to populate "ImgArray.add(image)" on GridView
}
}
Here is my ArrayList ImgArray result
Gallery Image Array: [http://fromwebsiteurl.net/media/image/0001.jpg, http://fromwebsiteurl.net/media/image/0002.jpg, http://fromwebsiteurl.net/media/image/0003
.jpg, http://fromwebsiteurl.net/media/image/0004.jpg, http://fromwebsiteurl.net/media/image/0005.jpg, http://fromwebsiteurl.net/media/image/0006.jpg, http://fromwebsiteurl.net/media/image/0007.jpg, http://fromwebsiteurl.net/media/image/0008.jpg, http://fromwebsiteurl.net/media/image/0009.jpg, http://fromwebsiteurl.net/media/image/0010.jpg, http://fromwebsiteurl.net/media/image/0011.jpg, http://fromwebsiteurl.net/media/image/0012.jpg, http://fromwebsiteurl.net/media/image/0013.jpg, http://fromwebsiteurl.net/media/image/0014.jpg, http://fromwebsiteurl.net/media/image/0015.jpg, http://fromwebsiteurl.net/media/image/0016.jpg, http://fromwebsiteurl.net/media/image/0017.jpg, http://fromwebsiteurl.net/media/image/0018.jpg, http://fromwebsiteurl.net/media/image/0019.jpg, http://fromwebsiteurl.net/media/image/0020.jpg]
Thanks in Advance