Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid adding image to dynamic listview
    primarykey
    data
    text
    <p>I have already created a dynamic list view that passes text to a SimpleAdapter, however I would like to pass information to make an image appear from the drawable folder. Here is the XML layout for each row:</p> <p> </p> <pre><code>&lt;ImageView android:id="@+id/sport_icon" android:layout_width="wrap_content" android:layout_height="wrap_content" /&gt; &lt;TextView android:id="@+id/item_title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:padding="2dp" android:textSize="20dp" /&gt; &lt;LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="right" &gt; &lt;TextView android:id="@+id/item_subtitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="2dp" android:textSize="13dp" /&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; </code></pre> <p></p> <p>and the bit of code creating the list:</p> <pre><code>//fill in the list items from the XML document for (int i = 0; i &lt; nodes.getLength(); i++) { HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;(); Element e = (Element)nodes.item(i); map.put("id", XMLfunctions.getValue(e, "fixture_id")); map.put("sport", XMLfunctions.getValue(e, "sport")); map.put("teams", XMLfunctions.getValue(e, "team_2") + " v " + XMLfunctions.getValue(e, "team_2")); mylist.add(map); } //Make a new listadapter ListAdapter adapter = new SimpleAdapter(this, mylist, R.layout.fixture, new String[] { "sport", "teams" }, new int[] { R.id.item_title, R.id.item_subtitle }); setListAdapter(adapter); </code></pre> <p>Now at the moment when I pass the string sport it just displays the text such as 'football' in the item_title text view. But as I know what the sport is I would like to be able to display an icon in the sport_icon imageview. An example of the sport icon location would be @drawable/icon_football.</p> <p>Many thanks.</p> <hr> <p>The answer here was creating a BaseAdapter with the ListView as suggested by Frank below. If anyone else is looking to do the same thing but has no idea where to start I highly recommend watching <a href="http://www.youtube.com/watch?v=pVs4qKmenQM" rel="nofollow">http://www.youtube.com/watch?v=pVs4qKmenQM</a>. This video is well put together and explains everything you need to know.</p> <p>:)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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