Mohammad Ersan
Mohammad Ersan

Reputation: 12444

How to change a view when another view is pressed/clicked

If i had Button btn1 and i had another Button btn2 how to connect the two views on the same events like onPress, onFocus.

let me explain:

when i press btn1 now the btn1 is pressed and colored with orange background while am pressing it, i wanna change btn2 state to be pressed and with background color orange.

any ideas?

Upvotes: 0

Views: 4044

Answers (3)

commanderdileep
commanderdileep

Reputation: 15

If You don't want the click event to be passed to btn2, do a btn2.callOnClick instead. It will call any onClick action listener associated with btn2. If there aren't any, it'll return false.

Upvotes: 0

Ravi Vyas
Ravi Vyas

Reputation: 12375

You can set a touch listener for Button1 where you can call Button2.setPressed(true) after checking the action of the event . i.e if you want it to be pressed only while Button1 is pressed you would call the function when Action is ACTION_DOWN and call it again with a false parameter when the Action is ACTION_UP. If you want button2 to remain pressed you can use the onClicklistener instead

Upvotes: 4

Sergey Glotov
Sergey Glotov

Reputation: 20356

Call manually performClick() (or similar method) of btn2 in the onPress() or onFocus() listeners of btn1.

Upvotes: 0

Related Questions