我在if else声明中遇到了一些问题,请支持
if (btn1.getText().toString().equals(myString[6]) &&
(btn1.getText().toString().equals(myString[6]) || (btn1.getText().toString().equals(myString[7]) || (btn1.getText().toString().equals(myString[8]) || (btn1.getText().toString().equals(myString[9]) || (btn1.getText().toString().equals(myString[10]) || (btn1.getText().toString().equals(myString[11]) || (btn1.getText().toString().equals(myString[12]) || (btn1.getText().toString().equals(myString[13]) || (btn1.getText().toString().equals(myString[14]) || (btn1.getText().toString().equals(myString[15])||
(btn2.getText().toString().equals(myString[6]) || (btn2.getText().toString().equals(myString[7]) || (btn2.getText().toString().equals(myString[8]) || (btn2.getText().toString().equals(myString[9]) || (btn2.getText().toString().equals(myString[10]) || (btn2.getText().toString().equals(myString[11]) || (btn2.getText().toString().equals(myString[12]) || (btn2.getText().toString().equals(myString[13]) || (btn2.getText().toString().equals(myString[14]) || (btn2.getText().toString().equals(myString[15])||
(btn3.getText().toString().equals(myString[6]) || (btn3.getText().toString().equals(myString[7]) || (btn3.getText().toString().equals(myString[8]) || (btn3.getText().toString().equals(myString[9]) || (btn3.getText().toString().equals(myString[10]) || (btn3.getText().toString().equals(myString[11]) || (btn3.getText().toString().equals(myString[12]) || (btn3.getText().toString().equals(myString[13]) || (btn3.getText().toString().equals(myString[14]) || (btn3.getText().toString().equals(myString[15])||
(btn4.getText().toString().equals(myString[6]) || (btn4.getText().toString().equals(myString[7]) || (btn4.getText().toString().equals(myString[8]) || (btn4.getText().toString().equals(myString[9]) || (btn4.getText().toString().equals(myString[10]) || (btn4.getText().toString().equals(myString[11]) || (btn4.getText().toString().equals(myString[12]) || (btn4.getText().toString().equals(myString[13]) || (btn4.getText().toString().equals(myString[14]) || (btn4.getText().toString().equals(myString[15])||
(btn5.getText().toString().equals(myString[6]) || (btn5.getText().toString().equals(myString[7]) || (btn5.getText().toString().equals(myString[8]) || (btn5.getText().toString().equals(myString[9]) || (btn5.getText().toString().equals(myString[10]) || (btn5.getText().toString().equals(myString[11]) || (btn5.getText().toString().equals(myString[12]) || (btn5.getText().toString().equals(myString[13]) || (btn5.getText().toString().equals(myString[14]) || (btn5.getText().toString().equals(myString[15])||
(btn01.getText().toString().equals(myString[6]) || (btn01.getText().toString().equals(myString[7]) || (btn01.getText().toString().equals(myString[8]) || (btn01.getText().toString().equals(myString[9]) || (btn01.getText().toString().equals(myString[10]) || (btn01.getText().toString().equals(myString[11]) || (btn01.getText().toString().equals(myString[12]) || (btn01.getText().toString().equals(myString[13]) || (btn01.getText().toString().equals(myString[14]) || (btn01.getText().toString().equals(myString[15])
)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))
{
Toast.makeText(getBaseContext(), "something wrong", Toast.LENGTH_SHORT).show();
}
else if (btn1.getText().toString() == (btn2.getText().toString())
(btn1.getText().toString() == (btn3.getText().toString())||
(btn1.getText().toString() == (btn4.getText().toString())||
(btn1.getText().toString() == (btn5.getText().toString())||
(btn1.getText().toString() == (btn01.getText().toString())||
(btn2.getText().toString() == (btn3.getText().toString())||
(btn2.getText().toString() == (btn4.getText().toString())||
(btn2.getText().toString() == (btn5.getText().toString())||
(btn2.getText().toString() == (btn01.getText().toString())||
(btn3.getText().toString() == (btn4.getText().toString())||
(btn3.getText().toString() == (btn5.getText().toString())||
(btn3.getText().toString() == (btn01.getText().toString())||
(btn4.getText().toString() == (btn5.getText().toString())||
(btn4.getText().toString() == (btn01.getText().toString())||
(btn5.getText().toString() == (btn01.getText().toString()))))))))))))))))
{
Toast.makeText(getBaseContext(), "something same", Toast.LENGTH_SHORT).show();
}
else (btn1.getText().toString().equals(myString[0])||
(btn1.getText().toString().equals(myString[1])||(btn1.getText().toString().equals(myString[2])||(btn1.getText().toString().equals(myString[3])||(btn1.getText().toString().equals(myString[4])||(btn1.getText().toString().equals(myString[5])))))))
{
Toast.makeText(getBaseContext(), "test", Toast.LENGTH_SHORT).show();
}
}
如果执行的语句只显示“相同”。我应该从上面的代码中添加什么?
答案 0 :(得分:3)
首先...... else if (btn1.getText().toString() == (btn2.getText().toString())....
使用.equals()
来比较String ..如果是梯形而不是其他的那么使用else,如果那样你可以检查一些问题......