a selector is a 'state-list-drawable', ie it 'selects' <items>
depending upon the state of the view it is applied to.
A StateListDrawable is a drawable object defined in XML that uses a several different images to represent the same graphic, depending on the state of the object. For example, a Button widget can exist in one of several different states (pressed, focused, or niether) and, using a state list drawable, you can provide a different background image for each state.
Here is the syntax, as in the docs :
<selector xmlns:android="http://schemas.android.com/apk/res/android"
android:constantSize=["true" | "false"]
android:dither=["true" | "false"]
android:variablePadding=["true" | "false"] >
<item
android:drawable="@[package:]drawable/drawable_resource"
android:state_pressed=["true" | "false"]
android:state_focused=["true" | "false"]
android:state_hovered=["true" | "false"]
android:state_selected=["true" | "false"]
android:state_checkable=["true" | "false"]
android:state_checked=["true" | "false"]
android:state_enabled=["true" | "false"]
android:state_activated=["true" | "false"]
android:state_window_focused=["true" | "false"] />
</selector>
notice the attributes you can set in the the <item>
.
here is an example of a typical selector..
<selector xmlns:android="http://schemas.android.com/apk/res/android"
>
<item
android:state_focused="true"
android:state_pressed="false"
android:drawable="@drawable/list_element_focused" />
<item
android:state_focused="true"
android:state_pressed="true"
android:drawable="@drawable/list_element_focused_pressed" />
<item
android:state_focused="false"
android:state_pressed="true"
android:drawable="@drawable/list_element_pressed" />
<item
android:drawable="@drawable/list_element_unfocused" />
</selector>
Please apply your selector in your listview instead of LinearLayout.