1

I am new in android apps development. Can anybody suggest me how to display images in a gridview using JSON parsing in android?

2 Answers 2

3

what exactly you want to do because json parsing and display images in gridview are two diffrent things. either you want to fatch image from server and use json parsing to parse URLs .Or make your question clear to understand by everyone.

Sign up to request clarification or add additional context in comments.

Comments

2

add this class in your project: JsonParser

public class ImageDownloader extends AsyncTask<String, Void, Bitmap> {

    @Override
    protected Bitmap doInBackground(String... params) {
        // TODO Auto-generated method stub

        Bitmap bitmap = null;
        try {

            URL aURL = new URL(params[0]);
            URLConnection conn = aURL.openConnection();
            conn.connect();
            InputStream is = conn.getInputStream();

            // Buffered is always good for a performance plus.
            BufferedInputStream bis = new BufferedInputStream(is);
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inSampleSize =5;
            // Decode url-data to a bitmap.
            bitmap = BitmapFactory.decodeStream(bis, null, options);

            // Close BufferedInputStream
            bis.close();

            // Close InputStream
            is.close();

            return bitmap;
        } catch (IOException e1) {
            e1.printStackTrace();
            return null;
        }

    }

in main activity:- add grid view and set adapter call the asyntask with your URL

ImageDownloader d=new ImageDownloder();
Bimap b=d.execute("url").get();
grid = (GridView) findViewById(R.id.grid);// grid view ti view all photos
AdapterForPics adap = new AdapterForPics(Arraylist, Context);
grid.setAdapter(adap);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.