Android BMI计算器中的Calculate按钮

Android BMI计算器中的Calculate按钮,android,Android,又是我。。。我想问一下,如果用户不输入他们的体重和身高,如何使我的“按钮”(calculateButton)不起作用。。。或者用户没有输入他们的体重或身高。。。希望你能帮助我。。。谢谢 以下是我的calculateButton的代码: public void calculateClickHandler(View view) { if (view.getId() == R.id.calculateButton) { } EditT

又是我。。。我想问一下,如果用户不输入他们的体重和身高,如何使我的“按钮”(calculateButton)不起作用。。。或者用户没有输入他们的体重或身高。。。希望你能帮助我。。。谢谢

以下是我的calculateButton的代码:

   public void calculateClickHandler(View view) {

    if (view.getId() == R.id.calculateButton) {

                }

        EditText weightText = (EditText) findViewById(R.id.weightT);
        EditText heightText = (EditText)findViewById(R.id.heightT);
        TextView resultText = (TextView)findViewById(R.id.resultLabel);
        TextView categoryText = (TextView)findViewById(R.id.categoryLabel);
        rGroup  = (RadioGroup)findViewById(R.id.rGroup);


    int weight = (int)  Float.parseFloat(weightText.getText().toString());
    int height = (int) Float.parseFloat(heightText.getText().toString());
        int bmiValue = calculateBMI(weight, height);

    String bmiInterpretation = interpretBMI(bmiValue);

    resultText.setText("Your BMI is:" + " " + bmiValue + " " + "and you're");
        categoryText.setText(bmiInterpretation + ".");}
您需要在代码中插入“验证”。在执行任何操作之前,基本上检查
编辑文本中
字符串的值

比如:

    rGroup  = (RadioGroup)findViewById(R.id.rGroup);

if( !weightText.getText().toString.equals(" ")){
    int weight = (int)  Float.parseFloat(weightText.getText().toString());
    int height = (int) Float.parseFloat(heightText.getText().toString());
        int bmiValue = calculateBMI(weight, height);
    }  
参考:



检查“.toString!=null”中的错误。。。它说的toString无法解析或者它不是一个字段…@deloy,这是你放置代码的地方,只是给了你一个想法,请研究一下验证和其他链接的相关代码