0

我在 if else 语句中有这段代码......我试图阻止 textview 值低于 0,但它仍然低于 0。

else if(iv1.getDrawable().getConstantState().equals(getResources().getDrawable(R.drawable.airplane2).getConstantState())){
                    int e =Integer.parseInt(textView5.getText().toString());
                    int f = e-1;
                    String s3 = String.valueOf(f);
                    textView5.setText(s3);
                    int dInt = Integer.parseInt(textView5.getText().toString());
                    if(dInt <= 0)
                                  {

                                       Toast.makeText(getApplicationContext(), "GameOver",Toast.LENGTH_SHORT).show();

                                  }

                }

PS对不起我的英语我已经减少了我的代码,但它仍然是负值

4

2 回答 2

0

Math.max 做你想做的事。

int b = Math.max(a - 2, 0);
于 2013-02-27T02:37:36.577 回答
0
if  (iv1.getDrawable().getConstantState().equals(getResources().getDrawable(R.drawable.airplane1).getConstantState())) {{
                    int a=Integer.parseInt(textView5.getText().toString());
                    int b=a+12;
                    String s1 = String.valueOf(b);
                    textView5.setText(s1);


                    Toast.makeText(getApplicationContext(), "Correct",
                            Toast.LENGTH_SHORT).show();
                }
                } int aInt = Integer.parseInt(textView5.getText().toString());
                 if(aInt <= 0) 
                 {
                     Toast.makeText(getApplicationContext(), "WrongWa",
                                Toast.LENGTH_SHORT).show();
                    } else if   (iv1.getDrawable().getConstantState().equals(getResources().getDrawable(R.drawable.airplane2).getConstantState())){

                     int c=Integer.parseInt(textView5.getText().toString());
                         int  d=c-2;
                      String s1 = String.valueOf(d);
                     textView5.setText(s1);
                     {
                     Toast.makeText(getApplicationContext(), "Wrong",
                                Toast.LENGTH_SHORT).show();
                     }
                    }
            }


            });

我已经尝试过了,它实际上以我希望 ito 成为 @Pragnani 的方式工作,感谢您的评论

于 2013-02-27T05:45:53.470 回答