How to synchronize the displayed state of two types

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>
+3
source share
2 answers

I think what you want android:focusable="true"in your RelativeLayout instead of clickable. I’m not sure what you mean by “How can I make my views transparent to touch events so they pass on to my parents?” When you click on EditText, do you want the onClick () buttons to be called?

0
source

, . ( ). , , :

// EDIT TEXT ON TOUCH HANDLER
editTextPassword.setOnTouchListener(new View.OnTouchListener() {    
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub  
            switch (event.getAction()){
                case MotionEvent.ACTION_DOWN:
                    SynchViews();  // view controller
                    break;
            }           
            return true;
        }
    });

// EDIT TEXT ON Click HANDLER (No touch screen)
editTextPassword.setOnClickListener(new OnClickListener() { 
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub  
                        SynchViews();   // view controller
        }
    });
0

All Articles