Well, what you're looking for is a way to propagate the parent state to its child views. Thus, when the state of the indicator changes (selected, but not), the state of the image changes.
Android already has an xml attribute for this.
android:duplicateParentState="true"
use this with your child views in the layout file and combine it with the selector. eg:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="#f00" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:text="Large Text" android:textAppearance="?android:attr/textAppearanceLarge" android:duplicateParentState="true" /> <ImageView android:id="@+id/imageView1" android:duplicateParentState="true" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center_horizontal" android:src="@drawable/selector" />
Mr. Me
source share