[英]How to change specify previous clicked image button view when the 2nd click button is occur
I have doubt in when I click the 2nd time image button, I want to change the both button image view in simultaneously. 我不确定在单击第二次图像按钮时是否要同时更改两个按钮的图像视图。
Example: 1. first time press the button 1 and change already the first time image view. 示例:1.第一次按按钮1并已更改第一次图像视图。 (get work) 2. second time press the other button 2 and I want change image view for the both button 1 and 2 in simultaneously.
(开始工作)2.第二次按另一个按钮2,我想同时同时更改两个按钮1和2的图像视图。 But I can only get the ibutton as variable signal to change the button 2 image view and button 1 can't get.
但是我只能将ibutton作为变量信号来更改按钮2的图像视图,而按钮1无法获得。
Question: 1. How do I change the button image view for button 1 when I click the button 2? 问题:1.单击按钮2时如何更改按钮1的按钮图像视图? 2. How do I can keep the button variable in array?
2.如何将按钮变量保留在数组中?
My code like this: 我的代码是这样的:
public class CheckersTest extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome);
final ImageView iv_new_game = (ImageView) findViewById(R.id.new_game);
iv_new_game.setOnClickListener(welcome_listener);
}
OnClickListener welcome_listener = new View.OnClickListener() {
public void onClick(View v) {
final ImageView iv = (ImageView) v;
if (iv.getId() == R.id.new_game) {
setContentView(R.layout.checkers_board);
final ImageButton b2 = (ImageButton) findViewById(R.id.imageButton2);
final ImageButton b4 = (ImageButton) findViewById(R.id.imageButton4);
final ImageButton b6 = (ImageButton) findViewById(R.id.imageButton6);
// set the OnClickListeners.
b2.setOnClickListener(button_listener);
b4.setOnClickListener(button_listener);
b6.setOnClickListener(button_listener);
// Re-enable the Click-able property of buttons.
b2.setClickable(true);
b4.setClickable(true);
b6.setClickable(true);
}
};
};
OnClickListener button_listener = new View.OnClickListener() {
public void onClick(View v) {
ImageButton ibutton = (ImageButton) v;
ibutton.setImageResource(R.drawable.green_bol);
}
};
在第二个Button的onclick
方法中,获取第一个按钮的实例并设置图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.