android - Accessing another view from a button's onclick event -
After
I am developing a simple game and in one activity I have 2 image buttons:
< code> & lt; Android: layout_height = "wrap_content" Android: Content Circles = "@ string / desc" Android: src = "@ drawable / img1" android: OnClick = "btn1_click" /> & Lt; Android: layout_height = "wrap_content" android: content = "@ string / desc" Android: src = "@ drawable / img2" Android: OnClick = "btn2_click" />And I'm showing some animation when the button is clicked:
Public Zero btn1_click (see v) {v.startAnimation (animLeftTranslate); } Public Zero btn2_click (see v) {v.startAnimation (animRightTranslate); }
Of course, only the clicked button is being animated but what do I want to do to show an animation for both buttons when one of them Clicked How Can You Do It?
You can accomplish this from your own point of view, which means that
android: OnClick attribute:
assign a function to both
ImageButton for example
btns_clicked () . Then add
android: onClick = 'btns_clicked' to both of your buttons and write that function:
public zeros btns_clicked (see v) {see btn1 = findViewById (R .id.btn1); See Btn2 = findViewById (R.id.btn2); btn1.startAnimation (animLeftTranslate); btn2.startAnimation (animRightTranslate); }
Comments
Post a Comment