so have listview, presenting custom views (each image + text). want views have different appearance when user selects them. (with overlay, try make work background)
if inflate row android.resource.layout.testlistitem
, works, cell shows selected state when click.
however, try similar effect custom layout, , can't work. missing ?
i have view layout :
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/rowbackground"> ... (textview , image)
and rowbackground.xml:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_selected="true" android:drawable="@drawable/bg_a" /> <item android:state_checked="true" android:drawable="@drawable/bg_b" /> <item android:state_pressed="true" android:drawable="@drawable/bg_c" /> <item android:state_selected="false" android:state_checked="false" android:state_pressed="false" android:drawable="@drawable/bg_d"/> </selector>
but 2 work "default" , "pressed" states. not "selected" one. (i tried checked, see in samples)
how can make custom-layout view selectable ?
ok actually, handle "selected" state in listview, have use activated selector (android:state_activated
), like:
<item android:state_activated="true" android:drawable="@drawable/ic_dep" />
of course doesn't seem documented anywhere. why, it's straightforward ? android
Comments
Post a Comment