Note that there are some explanatory texts on larger screens.

plurals
  1. POselect and highlight custom listview item
    primarykey
    data
    text
    <p>I want to position custom listview item</p> <pre><code>listView.setSelection(itemIndex); </code></pre> <p>Selected item positioning on the top of the visible part of listview. But not highlighted. How can i set default highlight of the listview item (then disable highlight and select another one) without listview re-create</p> <p>Thanks!</p> <p>p.s. I know it was asked many times before but i did not understand how it works</p> <p><strong>update</strong> not work on my android 2.2 (adt emulator and smartphone with android 2.2 froyo) </p> <p>drawable/listselector.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:drawable="@color/red" android:state_focused="true"/&gt; &lt;item android:drawable="@color/yellow" android:state_selected="true"/&gt; &lt;item android:drawable="@color/red" android:state_pressed="true"/&gt; &lt;/selector&gt; </code></pre> <p>values/colors.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;resources&gt; &lt;color name="black"&gt;#000000&lt;/color&gt; &lt;color name="white"&gt;#ffffff&lt;/color&gt; &lt;color name="yellow"&gt;#ffff00&lt;/color&gt; &lt;color name="red"&gt;#ff0000&lt;/color&gt; &lt;/resources&gt; </code></pre> <p>layout/list1.xml</p> <pre><code>&lt;ListView android:id="@android:id/list" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:background="@drawable/listselector" android:clickable="true" &gt; &lt;/ListView&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