title: ListView: Populate listview with images from JSON
body: <p>I have a listview which works perfectly when it comes to displaying all the text from a database through Php/JSON. However, in the database there is an image link associated with every item which I would like to show in the listview. Basically what it does is that a person clicks the search button and the default android search bar in action menu appears where they enter the word. Then it goes to the server and sends the word and tries to find all the matches from the database and pulls it. Now it works perfectly with displaying the textviews but for some reason I am unable to display images. Can someone show me how do it? I tried few times but I failed so hence the code I am providing you is my up to date code:</p>
  
  <pre><code>public class ListResult extends ListActivity {
  
      // Progress Dialog
      private ProgressDialog pDialog;
  
      // Creating JSON Parser object
      JSONParser jParser = new JSONParser();
  
      ArrayList&lt;HashMap&lt;String, String&gt;&gt; UserBooksList;
  
      // url to get the idiom list
      private static String url_search =   
      "http://randomurl.com/arandomapp/search.php";
  
      // JSON Node names
      private static final String TAG_SUCCESS = "success";
      private static final String TAG_UserBooks = "UserBooks";
      private static final String TAG_BName = "BName";
      private static final String TAG_NAME = "name";
  
      // THIS TAG BELOW IS THE ONE WHICH SHOWS THE IMAGE URL.
      private static final String TAG_IMG = "Id";
  
      // products JSONArray
      JSONArray user_books = null;
  
      // The keyword send to server and displays the result.
      public String search_key;
  
      TextView mError;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_list_result);
  
      // get the action bar
      ActionBar actionBar = getActionBar();
      actionBar.setDisplayHomeAsUpEnabled(true);
  
      if (savedInstanceState == null) {
          Bundle extras = getIntent().getExtras();
          if(extras == null) {
              search_key = null;
          } else {
              search_key = extras.getString("keyword");
          }
      } else {
          search_key = (String) savedInstanceState.getSerializable("keyword");
      }
  
      UserBooksList = new ArrayList&lt;&gt;();
  
      // Loading idioms in Background Thread
      new LoadIdioms().execute();
  
      mError = (TextView) findViewById(R.id.error);
      mError.setVisibility(View.GONE);
  
      actionBar.setTitle("Relevant Searches For: " + search_key);
      actionBar.setIcon(R.drawable.ic_action_search);
  }
  
  class LoadIdioms extends AsyncTask&lt;String, String, String&gt; {
  
      @Override
      protected void onPreExecute() {
          super.onPreExecute();
          pDialog = new ProgressDialog(ListResult.this);
          pDialog.setMessage("Loading Data. Please wait...");
          pDialog.setIndeterminate(false);
          pDialog.setCancelable(false);
          pDialog.show();
      }
  
      protected String doInBackground(String... args) {
  
          // Building Parameters
          List&lt;NameValuePair&gt; params = new ArrayList&lt;&gt;();
  
          //value captured from previous intent
          params.add(new BasicNameValuePair("keyword", search_key));
  
          // getting JSON string from URL
          JSONObject json = jParser.makeHttpRequest(url_search, "GET",    
  params);
  
          try {
  
              int success = json.getInt(TAG_SUCCESS);
  
              if (success == 1) {
  
                  user_books = json.getJSONArray(TAG_UserBooks);
  
                  for (int i = 0; i &lt; user_books.length(); i++) {
                      JSONObject c = user_books.getJSONObject(i);
  
                      // Storing each json item in variable
                      String bName = c.getString(TAG_BName);
                      String Name = c.getString(TAG_NAME);
                      String b_img = c.getString(TAG_IMG);
  
                      // creating new HashMap
                      HashMap&lt;String, String&gt; map = new HashMap&lt;&gt;();
  
                      // adding each child node to HashMap key =&gt; value
                      map.put(TAG_BName, bName);
                      map.put(Tag_NAME, Name);
                      map.put(TAG_IMG, b_img);
  
                      // adding HashList to ArrayList
                      UserBooksList.add(map);
  
                  }
              } else {
                  Log.d("Login Failure!", json.getString(TAG_MESSAGE));
                  return json.getString(TAG_MESSAGE);
              }
          } catch (JSONException e) {
              e.printStackTrace();
          }
  
          return null;
      }
  
      protected void onPostExecute(String file_url) {
  
          // dismiss the dialog after getting the related idioms
          pDialog.dismiss();
  
          // updating UI from Background Thread
          runOnUiThread(new Runnable() {
  
              public void run() {
                  /**
                   * Updating parsed JSON data into ListView
                   **/
  
                  ListAdapter adapter = new SimpleAdapter(
                          ListResult.this, UserBooksList,
                          R.layout.list_item, new String[] {TAG_BName, TAG_Name},
                          new int[] {R.id.BName, R.id.Name});
  
                  // updating listview
                  setListAdapter(adapter);
              }
          });
  
          // dismiss the dialog once product deleted
          pDialog.dismiss();
          if (file_url != null){
              mError = (TextView) findViewById(R.id.error);
              mError.setVisibility(View.VISIBLE);
              mError.setText("Sorry, No Books were found. Please try again.");
          }
      }
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      MenuInflater inflater = getMenuInflater();
      inflater.inflate(R.menu.activity_main_actions_two, menu);
  
      return super.onCreateOptionsMenu(menu);
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      // Take appropriate action for each action item click
      switch (item.getItemId()) {
          case R.id.action_help:
              // help action
              return true;
          default:
              return super.onOptionsItemSelected(item);
      }
  }
  }
  </code></pre>
  
  <p>Can anyone suggest to me how I would incorporate the idea of also setting the images while its loading? I mean the url's of the images are being fetched perfectly when I tried it. </p>
  
  <p>I have a <code>list_item.xml</code> which contains the textview for the name and an imageView which has an id: ImageView3.</p>
  
  <p>THANKS :) </p>