0

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

Baloch
  • 3
  • 2

1 Answers1

0

You haven't said what you want to do, but I think it's about to load images from urls, here is an example. And then you just have to put bitmaps in ImageViews and put these in your grid.

Community
  • 1
  • 1
Kyu_
  • 800
  • 4
  • 10
  • 18
  • I want to display images on GridView from JSON URL, Check Gallery Image Array values <= I want to show these images GridView. Thanks for above example but it only showing 1 image. – Baloch Jun 03 '14 at 10:04
  • Put the code in your for() to apply it to all images and store it in a Vector and put these in the gridView in the onPostExecute() – Kyu_ Jun 03 '14 at 10:07
  • Sorry I'm new in Android development, can you please share some sample code. – Baloch Jun 03 '14 at 10:21