我尝试为android设计一个应用程序。在java中更改变量值
我想,轻敲按钮1,x
设置为1,并为BUTTON2 y
设置为1,等等。当
然后在if语句中使用这些变量。
int z;
int y;
int w;
final Button m = (Button) findViewById(R.id.button1);
final Button m1 = (Button) findViewById(R.id.button4);
final Button m2 = (Button) findViewById(R.id.button5);
m.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
// some code here
z == 1;
return false;
}
});
m1.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
// some code here
z == 1;
return false;
}
});
m2.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
// some code here
z == 1;
return false;
}
});
if (x == 1 & y == 1 & z == 1) {
finish();
//some code here
}
但是“if”内部块永远不会到达;我该如何解决这个问题?
谢谢。
你应该学会如何正确地格式化代码。关于你的问题:Hexafraction是正确的。你必须使用一个等号来为你的变量赋值。 – Ahmad
您应该使用'&&'作为逻辑,并且像这样'if(x == 1 && y == 1 && z == 1)'。一个'&'是一个按位运算符,如果一切都是奇数,但不会按照您的想法操作,则该运算符将起作用。 – Simon
==只是错的类型 我的问题:“如果”没有工作(我试过&&但还没有工作) – meysam