开发者

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 pressin开发者_运维技巧g it, i wanna change btn2 state to be pressed and with background color orange.

any ideas?


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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜