Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8037793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:01:44+00:00 2026-06-05T03:01:44+00:00

I am getting json data. In that json I have a url for an

  • 0

I am getting json data. In that json I have a url for an image. Now I want to display that Image in ImageView. How can I do acheive this? Here is my code

class LoadInbox extends AsyncTask<String, String, String> {
    /**
     * Before starting background thread Show Progress Dialog
     * */
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(Home.this);
        pDialog.setMessage("Loading Inbox ...");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(false);
        pDialog.show();
    }

    /**
     * getting Inbox JSON
     * */
 protected String doInBackground(String... arg0) {
        // Building Parameters
        List<NameValuePair> params = new ArrayList<NameValuePair>();

        JSONObject json = userFunctions.homeData();

        Log.e("Data", json.toString());

        // Check your log cat for JSON reponse
        Log.d("Inbox JSON: ", json.toString());

        try {
            data = json.getJSONArray(TAG_DATA);
            Log.d("inbox array: ", data.toString());
            // looping through All messages
            for (int i = 0; i < data.length(); i++) {
                JSONObject c = data.getJSONObject(i);

                // Storing each json item in variable
                String profile_img = c.getString(TAG_PROFILE_IMG);

                // creating new HashMap
                HashMap<String, String> map = new HashMap<String, String>();

                // adding each child node to HashMap key => value
                map.put(TAG_PROFILE_IMG, profile_img);

                // adding HashList to ArrayList
                inboxList.add(map);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;
    }
protected void onPostExecute(String file_url) {
        // dismiss the dialog after getting all products
        pDialog.dismiss();
        // updating UI from Background Thread
        runOnUiThread(new Runnable() {
            public void run() {
                /**
                 * Updating parsed JSON data into ListView
                 * */
                ListAdapter adapter = new SimpleAdapter(
                        Home.this, inboxList,
                        R.layout.home_list_item, new String[] { TAG_PROFILE_IMG },
                        new int[] { R.id.profile_img2 });
                // updating listview
                setListAdapter(adapter);
            }
        });

    }

here is my layout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<ImageView 
    android:id="@+id/profile_img2" 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingTop="8dip"
    android:paddingLeft="8dip"
    android:paddingBottom="4dip" />
</RelativeLayout>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T03:01:45+00:00Added an answer on June 5, 2026 at 3:01 am

    So you’ll want to create another AsyncTask that given a URL will load the image, and populate some control. I typically do something like this:

    ImageView imageView = (ImageView)findById(R.id.blah);
    new ImageLoader( person.getImageUri(), imageView, 128, 128 ).execute();
    

    The ImageLoader would be another AsyncTask like this:

    public class ImageLoader extends AsyncTask<URI,Integer,BitmapDrawable> {
        private Uri imageUri;
    
        private ImageView imageView;
    
        private int preferredWidth = 80;
        private int preferredHeight = 80;
    
        public ImageLoader( URI uri, ImageView imageView, int scaleWidth, int scaleHeight ) {
            this.imageUri = uri;
            this.imageView = imageView;
            this.preferredWidth = scaleWidth;
            this.preferredHeight = scaleHeight;
        }
    
        public BitmapDrawable doInBackground(URI... params) {
        if( imageUri == null ) return null;
        String url = imageUri.toString();
        if( url.length() == 0 ) return null;
        HttpGet httpGet = new HttpGet(url);
        DefaultHttpClient client = new DefaultHttpClient();
        HttpResponse response = client.execute( httpGet );
        InputStream is = new BufferedInputStream( response.getEntity().getContent() );
        try {
            Bitmap bitmap = BitmapFactory.decodeStream(is);
            if( preferredWidth > 0 && preferredHeight > 0 && bitmap.getWidth() > preferredWidth && bitmap.getHeight() > preferredHeight ) {
                return Bitmap.createScaledBitmap(bitmap, preferredWidth, preferredHeight, false);
            } else {
                return bitmap;
            }
        } finally {
            is.close();
        }
        }
    }
    
        public void onPostExecute( BitmapDrawable drawable ) {
            imageView.setImageBitmap( drawable );
        }
    }
    

    Then you can kick this AsyncTask off when the image is being bound in your ListView by creating your own subclass ListAdapter. So you’ll have to ditch using SimpleAdapter because things aren’t simple anymore. This has a lot of advantages so you only load the images being displayed. That means a very small number is loaded out of the total. Also your user can see the data before the image loads so quicker access to the data. If you did this in your existing AsyncTask you’d load every image, and the user would have to wait for every single one to finish before the data is shown to the user. There are somethings that can be improved by this. One AsyncTask uses its own thread so you’ll be running a lot of threads potentially (10 or more) all at once. That can kill your server with lots of clients. You can centralize these using an ExecutorService (ie thread pool) but you’ll have to ditch using AsyncTask and implement your own facility to run the job off the UI thread and post the results back on the UI thread. Second, your images will load every time the user scrolls. For this I implemented my own caching scheme based on the URI of the image so I only load the image once and return it from the cache. It’s a little too much code to post here, but these are exercises for the reader.

    Also notice I’m not posting back to the UI thread in onPostExecute(). That’s because AsyncTask does that for me I don’t have to do it again as your code above shows. You should just remove that extra runnable and inline the code in onPostExecute().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting JSON string from website. I have data which looks like this
I'm have trouble grabbing the response JSON data that's returned via AJAX call. Here
I m getting Time data in this format in an JSON Object. created_time: 2012-04-01T15:02:52+0000
I have a function var url = MyAvailability.aspx?mode=get; $.get(url, function(data) { alert(data); }); that
I have the following JSON: {COLUMNS:[ID,FIRSTNAME],DATA:[[1,Steve],[2,Jim],[3,Bill],[4,Tony]]} I am trying to write some jQuery that
I have a data Store that gets it's information from a JSON api on
Im calling a url and getting json data back, If there is no data
I'm having a little dilemma with an iphone project. I'm getting some JSON data
I am iterating through a JSON object and I am getting the data and
I am getting JSON response from the server..Inside that JSON string i am having

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.