0

我有这个 if else 语句的代码

@Override
        public void onClick(View arg0) {
            int aInt = Integer.parseInt(textView1.getText().toString());
             if(aInt <= 0) {
                 Toast.makeText(getApplicationContext(), "Wrong",
                            Toast.LENGTH_SHORT).show();
                } else{

                 int a=Integer.parseInt(textView1.getText().toString());
                     int  b=a-2;
                  String s1 = String.valueOf(b);
                 textView1.setText(s1);
                 Toast.makeText(getApplicationContext(), "Wrong",
                            Toast.LENGTH_SHORT).show();
                int c =Integer.parseInt(textView5.getText().toString());
                        int d = c-1;
                        String s2 = String.valueOf(d);
                        textView5.setText(s2);

                }  if(textView5 != null) {
                    int dInt = Integer.parseInt(textView5.getText().toString());
                        if(dInt <= 0);
                     Toast.makeText(getApplicationContext(), "Game Over",
                                Toast.LENGTH_SHORT).show();
                            Intent intent = new Intent();
                        intent.setClass(MainActivity.this, Fifth.class);
                        startActivity(intent);

                    SavePreferences("MEM1", textView1.getText().toString());
                }
        }

};

在这部分代码上,如果 textView5 的值为 0,我想启动意图,但即使 textView5 的值还不是 0,它仍然会进入新的意图,我不知道我的代码的哪一部分是错误的:

}  if(textView5 != null) {
                int dInt = Integer.parseInt(textView5.getText().toString());
                    if(dInt <= 0);
                 Toast.makeText(getApplicationContext(), "Game Over",
                            Toast.LENGTH_SHORT).show();
                        Intent intent = new Intent();
                    intent.setClass(MainActivity.this, Fifth.class);
                    startActivity(intent);
 }
4

5 回答 5

0
if(textView5 != null)
{
      int dInt = Integer.parseInt(textView5.getText().toString());
      if(dInt <= 0)
                {
                     Toast.makeText(getApplicationContext(), "Game Over",Toast.LENGTH_SHORT).show();
                    startActivity(new Intent(MainActivity.this, Fifth.class));
                }
     }
于 2013-02-18T10:24:34.127 回答
0

这样做:

}  if(textView5 != null) {
            int dInt = Integer.parseInt(textView5.getText().toString());
                if(dInt <= 0) {
             Toast.makeText(getApplicationContext(), "Game Over",
                        Toast.LENGTH_SHORT).show();
                    Intent intent = new Intent();
                intent.setClass(MainActivity.this, Fifth.class);
                startActivity(intent);
              }
}
于 2013-02-18T10:24:49.700 回答
0

试试这个:如果没有像这样的分号循环

  if(dInt <= 0){
         Toast.makeText(getApplicationContext(), "Game Over",
                    Toast.LENGTH_SHORT).show();
                Intent intent = new Intent();
            intent.setClass(MainActivity.this, Fifth.class);
            startActivity(intent);
            }
于 2013-02-18T10:27:44.467 回答
0

语句(textView5 != null) 检查 view 是否不为 null。您需要添加编辑代码,例如 .

                   if(!textView5.getText().toString().equals("")) {
            int dInt = Integer.parseInt(textView5.getText().toString());
                if(dInt <= 0);
             Toast.makeText(getApplicationContext(), "Game Over",
                        Toast.LENGTH_SHORT).show();
                    Intent intent = new Intent();
                intent.setClass(MainActivity.this, Fifth.class);
                startActivity(intent);
                }
于 2013-02-18T10:26:27.707 回答
-1

;是字符串的结尾。如果您;在 If 条件结束时给出,则正文不会执行..

所以删除它并检查你的代码..

if(dInt <= 0)
   Toast.makeText(getApplicationContext(), "Game Over",Toast.LENGTH_SHORT).show();
   Intent intent = new Intent();
   ......
于 2013-02-18T10:26:09.350 回答