Note that there are some explanatory texts on larger screens.

plurals
  1. POBackground each row in listview
    primarykey
    data
    text
    <p>I'm trying to customize a <code>ListView</code> to have a default background image and highlighted background image for each single row.</p> <p>However, the highlighted background image affects single rows, and the default background image affects the whole <code>ListView</code>; but I need it to affect each single row. </p> <p>Could somebody tell me how to do this?</p> <p>This is my code:</p> <p><strong>layout/main.xml:</strong></p> <pre><code>&lt;ListView android:id="@+id/list" android:layout_width="match_parent" android:layout_height="wrap_content" android:dividerHeight="1dip" android:listSelector="@drawable/bg_highlighted" /&gt; </code></pre> <p><strong>drawable/selector.xml:</strong></p> <pre><code>&lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:state_selected="true" android:drawable="@drawable/bg_default"/&gt; &lt;item android:state_focused="true" android:drawable="@drawable/bg_default"/&gt; &lt;/selector&gt; </code></pre> <p><strong>src/main.java:</strong></p> <pre><code> ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;( this,R.layout.list, mStrings); /*"Item1","Item2","Item3","Item4"*/ ListView lv = (ListView)findViewById(R.id.list); lv.setAdapter(adapter); lv.setBackgroundResource(R.drawable.selector); </code></pre> <p>As default background and highlighted background I use png images.</p> <p><a href="http://i.stack.imgur.com/JNLVo.png" rel="nofollow">This is what I have</a>, but <a href="http://i.stack.imgur.com/LdLqz.png" rel="nofollow">this is what I want</a>.</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.
 

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