Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I set drawable to a ListView in android
    primarykey
    data
    text
    <p>I am writing a app for android 1.5. I want to use a complex listview to display my data. I want to show a ImageView of a drawable object in my List item.</p> <p>I learned from a demo:</p> <pre><code>------&gt; listData.put("Img", listData.put("Img", R.drawable.XXX)); listData.put("Time", "100"); listItems.add(listData); </code></pre> <p>It can display correctly, however, I want to change Img at runtime, The image maybe generated at run-time, so I change the code as follow, but it falls. Can anyone help me ? many thanks!</p> <pre><code>protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.item_list); itemListView = (ListView) findViewById(R.id.listview); ArrayList&lt;HashMap&lt;String, Object&gt;&gt; listItems = new ArrayList&lt;HashMap&lt;String, Object&gt;&gt;(); for(int i = 0;i &lt;XXX.size(); ++i) { HashMap&lt;String, Object&gt; listData = new HashMap&lt;String, Object&gt;(); ---------&gt;/*1)*/ listData.put("Img", new Drawable(XXX)); /*2)*/ listData.put("Time", "100"); /*3)*/ listItems.add(listData); } SimpleAdapter listItemAdapter = new SimpleAdapter(this, listItems, R.layout.listitem, new String[] { "Img", "Time"}, new int[] { R.id.listitem_img, R.id.listitem_time }); itemListView.setAdapter(listItemAdapter); } </code></pre> <p>listitem.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout android:layout_width="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:paddingBottom="4dip" android:paddingLeft="12dip" android:paddingRight="12dip"&gt; &lt;ImageView android:id="@+id/listitem_img" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingTop="12dip"/&gt; &lt;TextView android:id="@+id/listitem_time" android:layout_height="wrap_content" android:layout_width="wrap_content" android:textSize="20dip" /&gt; &lt;/LinearLayout&gt; </code></pre>
    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.
 

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