java - select and highlight custom listview item -


i want position custom listview item

listview.setselection(itemindex); 

selected item positioning on top of visible part of listview. not highlighted. how can set default highlight of listview item (then disable highlight , select one) without listview re-create

thanks!

p.s. know asked many times before did not understand how works

update not work on android 2.2 (adt emulator , smartphone android 2.2 froyo)

drawable/listselector.xml

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android">  <item android:drawable="@color/red" android:state_focused="true"/> <item android:drawable="@color/yellow" android:state_selected="true"/> <item android:drawable="@color/red" android:state_pressed="true"/>  </selector> 

values/colors.xml

<?xml version="1.0" encoding="utf-8"?> <resources>      <color name="black">#000000</color>     <color name="white">#ffffff</color>     <color name="yellow">#ffff00</color>     <color name="red">#ff0000</color> </resources> 

layout/list1.xml

<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" > </listview> 

you need selector add layout in xml

android:clickable="true" android:background="@drawable/selector" 

and create selecor.xml in drawable folder this

<?xml version="1.0" encoding="utf-8"?>  <selector xmlns:android="http://schemas.android.com/apk/res/android">        <item android:state_selected="true"          android:drawable="@color/red"/>   </selector> 

and finaly @ values folder in colors.xml

<?xml version="1.0" encoding="utf-8"?>     <resources>         <color name="black">#000000</color>          <color name="white">#ffffff</color>         <color name="red">#ff0000</color>     </resources> 

and call

listview.requestfocusfromtouch(); 

before

listview.setselection(itemindex); 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -