In Android, I have an EditText and a button next to EditText, and whenever I click on it, I would like the other to display in the same state.
I tried putting android: clickable = "true" on the attached layout and android: duplicateParentState = "true" on my EditText and Button, but this only works if I touch the layout itself. If I touch my EditText or Button, nothing will happen. I tried setting android: clickable = "false" on EditText and Button, but touch events are still not filtered to the parent.
How can I make my views transparent in order to direct events so that they pass to the parent? I want EditText and Button to work together, so if I touch one of them, both of them seem to be pressed.
Here is the XML that I am currently using:
<RelativeLayout
android:id = "@+id/EnclosingLayout"
android:layout_width = "fill_parent"
android:layout_height = "120dp"
android:clickable = "true">
<EditText
android:id = "@+id/MyEditText"
android:layout_width = "fill_parent"
android:layout_height = "wrap_content"
android:layout_weight = "1"
android:focusable="false"
android:focusableInTouchMode="false"
android:clickable="false"
android:duplicateParentState="true"/>
<Button
android:id = "@+id/MyButton"
android:layout_alignTop="@id/MyEditText"
android:layout_alignBottom="@id/MyEditText"
android:layout_alignParentRight="true"
android:duplicateParentState="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_width="31.33dp"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:clickable="false"/>
</RelativeLayout>
Kevin source
share