【发布时间】:2014-03-15 17:31:30
【问题描述】:
我的 xml 中有这个按钮
我想使用它两次,一次用于更改另一个按钮的值,第二次用于像以前一样获取值。
这就是我所拥有的:
public void cambia(View view) {
boolean a = true;
Button boton1 = (Button)this.findViewById(R.id.btnDividir);
Button boton2 = (Button)this.findViewById(R.id.btnMultiplicar);
Button boton3 = (Button)this.findViewById(R.id.btnRestar);
Button boton4 = (Button)this.findViewById(R.id.btnSumar);
if (a == true) {
boton1.setText("/");
boton2.setText("*");
boton3.setText("-");
boton4.setText("+");
a = false;
} else if(a == false) {
boton1.setText("divide");
boton2.setText("multiplica");
boton3.setText("resta");
boton4.setText("suma");
a = true;
}
}
但我的变量 a 将始终具有 true 值,所以,当用户想要更改或恢复原样时,如何使用该按钮设置文本?
【问题讨论】:
-
你可以使用切换按钮