title: Adding a image from url to a ListView
body: <p>I am using a modified version of the <a href="http://www.androidhive.info/2012/01/android-json-parsing-tutorial/" rel="nofollow">contacts project from AndroidHive</a>.</p>
  
  <p>It basically just pulls n list of articles and their contact from a Joomla Site.</p>
  
  <p>I am using a <a href="https://github.com/koush/UrlImageViewHelper" rel="nofollow">Image Plugin</a> that gets a image from a url. i can successfully use it on the article detail activity view but i don't know how to add it to each List Item on the MainAcitivity file. I am new to Android development so please excuse the confusion.</p>
  
  <p>The script to add the image is:</p>
  
  <pre><code>ImageView thumb = (ImageView) findViewById(R.id.thumb);
  UrlImageViewHelper.setUrlDrawable(thumb, "https://www.site.co.za/test.png");
  </code></pre>
  
  <p>and my MainActivity which generated the ListView:</p>
  
  <pre><code>public class MainActivity extends ListActivity {
  
      private ProgressDialog pDialog;
  
      // URL to get articles JSON
      private static String url = "http://192.168.12.21/sebastian/broadcast/index.php/blog?format=json";
  
      // JSON Node names
      private static final String TAG_ARTICLES = "articles";
  
      // Get the fields
      private static final String TAG_ID = "id";
      private static final String TAG_TITLE = "title";
      private static final String TAG_SHORTTEXT = "shorttext";
      private static final String TAG_FULLTEXT = "fulltext";
      private static final String TAG_IMAGE = "image";
      private static final String TAG_DATE = "date";
  
      // articles JSONArray
      JSONArray articles = null;
  
      // Hashmap for ListView
      ArrayList&lt;HashMap&lt;String, String&gt;&gt; articleList;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          articleList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  
          ListView lv = getListView();
  
          // Listview on item click listener
          lv.setOnItemClickListener(new OnItemClickListener() {
  
              @Override
              public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                      int position, long id) {
                  // getting values from selected ListItem
                  String title = ((TextView) view.findViewById(R.id.title)).getText().toString();
                  String shorttext = ((TextView) view.findViewById(R.id.shorttext)).getText().toString();
                  String fulltext = ((TextView) view.findViewById(R.id.fulltext)).getText().toString();
                  String image = ((TextView) view.findViewById(R.id.image)).getText().toString();
                  String date = ((TextView) view.findViewById(R.id.date)).getText().toString();               
  
                  // Starting single article activity
                  Intent in = new Intent(getApplicationContext(),
                          SingleArticleActivity.class);
  
                  in.putExtra(TAG_TITLE, title);
                  in.putExtra(TAG_SHORTTEXT, shorttext);
                  in.putExtra(TAG_FULLTEXT, fulltext);
                  in.putExtra(TAG_IMAGE, image);
                  in.putExtra(TAG_DATE, date);
  
                  startActivity(in);
  
              }
          });
  
          // Calling async task to get json
          new GetArticles().execute();
  
      }
  
      /**
       * Async task class to get json by making HTTP call
       * */
      private class GetArticles extends AsyncTask&lt;Void, Void, Void&gt; {
  
          @Override
          protected void onPreExecute() {
              super.onPreExecute();
              // Showing progress dialog
              pDialog = new ProgressDialog(MainActivity.this);
              pDialog.setMessage("Please wait...");
              pDialog.setCancelable(false);
              pDialog.show();
  
          }
  
          @Override
          protected Void doInBackground(Void... arg0) {
              // Creating service handler class instance
              ServiceHandler sh = new ServiceHandler();
  
              // Making a request to url and getting response
              String jsonStr = sh.makeServiceCall(url, ServiceHandler.GET);
  
              Log.d("Response: ", "&gt; " + jsonStr);
  
              if (jsonStr != null) {
                  try {
                      JSONObject jsonObj = new JSONObject(jsonStr);
  
                      // Getting JSON Array node
                      articles = jsonObj.getJSONArray(TAG_ARTICLES);
  
                      // looping through All articles
                      for (int i = 0; i &lt; articles.length(); i++) {
                          JSONObject c = articles.getJSONObject(i);
  
                          String id = c.getString(TAG_ID);
                          String title = c.getString(TAG_TITLE);
                          String shorttext = c.getString(TAG_SHORTTEXT);
                          String fulltext = c.getString(TAG_FULLTEXT);                        
                          String image = c.getString(TAG_IMAGE);
                          String date = c.getString(TAG_DATE);
  
  
                          // tmp hashmap for single article
                          HashMap&lt;String, String&gt; article = new HashMap&lt;String, String&gt;();
  
                          // adding each child node to HashMap key =&gt; value
                          article.put(TAG_ID, id);
                          article.put(TAG_TITLE, title);
                          article.put(TAG_SHORTTEXT, shorttext);
                          article.put(TAG_FULLTEXT, fulltext);                        
                          article.put(TAG_IMAGE, image);
                          article.put(TAG_DATE, date);
  
                          // adding article to article list
                          articleList.add(article);
                      }
                  } catch (JSONException e) {
                      e.printStackTrace();
                  }
              } else {
                  Log.e("ServiceHandler", "Couldn't get any data from the url");
              }
  
              return null;
          }
  
          @Override
          protected void onPostExecute(Void result) {
              super.onPostExecute(result);
              // Dismiss the progress dialog
              if (pDialog.isShowing())
                  pDialog.dismiss();
              /**
               * Updating parsed JSON data into ListView
               * */
              ListAdapter adapter = new SimpleAdapter(
  
                      MainActivity.this, articleList,
                      R.layout.list_item, new String[] {
                                  TAG_TITLE,
                                  TAG_SHORTTEXT,
                                  TAG_FULLTEXT,
                                  TAG_IMAGE,
                                  TAG_DATE
                              },
                              new int[] {
                                  R.id.title,
                                  R.id.shorttext,
                                  R.id.fulltext,
                                  R.id.image,
                                  R.id.date                               
                              });
  
              setListAdapter(adapter);            
  
          }
  
      }
  
  }
  </code></pre>
  
  <p>**I don't know where in the MainActivity file do i add the script to add an image to each List Item.</p>
  
  <p>I already got it working on the SingleArticleActivity but cannot get it to work on the List of Items**</p>
  
  <p>Thanks for the help</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>What im trying to do:</p>
  
  <pre><code>foreach(ListItem in the List) {
  
      ImageView thumb = (ImageView) findViewById(R.id.thumb);
      UrlImageViewHelper.setUrlDrawable(thumb, "https://www.site.co.za/test.png");
  
  }
  </code></pre>