Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The icon did not show up because your <code>ListView</code> row does not contain an <code>ImageView</code> or anything else that would represent an icon.</p> <p>So, design your own row layout that contains an <code>ImageView</code> or something. Use that row layout to replace <code>android.R.layout.simple_list_item_2</code> when creating your <code>ArrayAdapter</code>. Then, in <code>getView()</code>, populate that <code>ImageView</code>.</p> <p><a href="https://github.com/commonsguy/cw-omnibus/tree/master/Selection/Dynamic" rel="nofollow">Here is a sample project</a> demonstrating putting an icon in <code>ListView</code> rows. The row contains an <code>ImageView</code>:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"&gt; &lt;ImageView android:id="@+id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:padding="2dip" android:src="@drawable/ok" android:contentDescription="@string/icon"/&gt; &lt;LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical"&gt; &lt;TextView android:id="@+id/label" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="25sp" android:textStyle="bold"/&gt; &lt;TextView android:id="@+id/size" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="15sp"/&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; </code></pre> <p>and the <code>ArrayAdapter</code> uses that row:</p> <pre><code>class IconicAdapter extends ArrayAdapter&lt;String&gt; { IconicAdapter() { super(DynamicDemo.this, R.layout.row, R.id.label, items); } @Override public View getView(int position, View convertView, ViewGroup parent) { View row=super.getView(position, convertView, parent); ImageView icon=(ImageView)row.findViewById(R.id.icon); if (items[position].length()&gt;4) { icon.setImageResource(R.drawable.delete); } else { icon.setImageResource(R.drawable.ok); } TextView size=(TextView)row.findViewById(R.id.size); size.setText(String.format(getString(R.string.size_template), items[position].length())); return(row); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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