Note that there are some explanatory texts on larger screens.

plurals
  1. POListAdapter and Set image from web
    text
    copied!<p>I am trying to create a list of products with images of each product in a list view. The content is pulled from the web.</p> <p>I have managed to create the list view with the name of each product and when each list item is clicked it shows the products image. However I want the images to show when the list is generated and I am not sure how to do this.</p> <p>I would really appreciate any help. Heres my code for the activiy:</p> <pre><code>NodeList nodes = doc.getElementsByTagName("result"); // Drawable d = null; for (int i = 0; i &lt; nodes.getLength(); i++) { // HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;(); HashMap&lt;String, Object&gt; map = new HashMap&lt;String, Object&gt;(); Element e = (Element) nodes.item(i); map.put("id", "ID: " + XMLfunctions.getValue(e, "id")); map.put("name", "Name: " + XMLfunctions.getValue(e, "name")); Drawable d = dManager .fetchDrawable("http://MY_WEBSITE/images/" + XMLfunctions.getValue(e, "image")); map.put("image", d); map.put("imageUrl", XMLfunctions.getValue(e, "image")); mylist.add(map); } ListAdapter adapter = new SimpleAdapter(this, mylist, R.layout.products, new String[] { "image", "name", "id", }, new int[] { R.id.item_image, R.id.item_title, R.id.item_subtitle }); setListAdapter(adapter); final ListView lv = getListView(); lv.setTextFilterEnabled(true); lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { @SuppressWarnings("unchecked") HashMap&lt;String, Object&gt; o = (HashMap&lt;String, Object&gt;) lv .getItemAtPosition(position); //Toast.makeText(productsActivity.this, "ID '" + o.get("id") + //"' was clicked.", Toast.LENGTH_LONG).show(); Drawable d = dManager .fetchDrawable("http://MY_WEBSITE/images/" + o.get("imageUrl")); ImageView imgView = (ImageView) view .findViewById(R.id.item_image); o.put("image", d); imgView.setImageDrawable(d); } }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload