0

我对 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();
            }
        }

如果执行的语句只出现“相同的东西”。我应该从上面的代码中添加什么?

4

1 回答 1

3

第一的....else if (btn1.getText().toString() == (btn2.getText().toString())....

用于.equals()比较 String..and 使用 else if ledder 而不是 else if then you can check some questions...

于 2012-04-23T04:09:39.657 回答