3

我正在尝试计算女性的 BMR,但微调器给了我错误:

09-01 22:08:52.373: E/AndroidRuntime(344):  at com.fps.iHealthFirst.BMRCalculator.onClick(BMRCalculator.java:286)
09-01 22:08:52.373: E/AndroidRuntime(344):  at android.view.View.performClick(View.java:2485)
09-01 22:08:52.373: E/AndroidRuntime(344):  at android.view.View$PerformClick.run(View.java:9080)
09-01 22:08:52.373: E/AndroidRuntime(344):  at android.os.Handler.handleCallback(Handler.java:587)
09-01 22:08:52.373: E/AndroidRuntime(344):  at android.os.Handler.dispatchMessage(Handler.java:92)
09-01 22:08:52.373: E/AndroidRuntime(344):  at android.os.Looper.loop(Looper.java:123)
09-01 22:08:52.373: E/AndroidRuntime(344):  at android.app.ActivityThread.main(ActivityThread.java:3683)
09-01 22:08:52.373: E/AndroidRuntime(344):  at java.lang.reflect.Method.invokeNative(Native Method)
09-01 22:08:52.373: E/AndroidRuntime(344):  at java.lang.reflect.Method.invoke(Method.java:507)
09-01 22:08:52.373: E/AndroidRuntime(344):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-01 22:08:52.373: E/AndroidRuntime(344):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-01 22:08:52.373: E/AndroidRuntime(344):  at dalvik.system.NativeStart.main(Native Method)

以及下面的代码,试图获得久坐、轻度活跃、中度活跃和高度活跃的微调器的价值:

private void calculateWomen(){

    String f1a = etft.getText().toString();
    String f2a = etin.getText().toString();
    String f3a = etweight.getText().toString();
    String f4a = etage.getText().toString();

    if ( ( f1a.isEmpty() || f2a.isEmpty() || f3a.isEmpty() || f4a.isEmpty() ) ) 
        // call for custom toast
        viewErrorToast();
    else{
    // Metric Formula for BMR (Women) English Unit
    //655 + ( 4.3379 x weight in pounds ) + 
    //( 4.6980 x height in inches ) - ( 4.6756 x age in years )
     String age, in, ft, weight;
     Double answer;

     age =  etage.getText().toString();
     in =  etin.getText().toString();    
     ft = etft.getText().toString();
     weight = etweight.getText().toString();


        if (spinnerText.equals("Sedentary")){
            //actAnswer = "1.2";
             answer =  ( ( 665 + ( 4.3379 * Double.parseDouble( weight ) ) + 
                     ( 4.6980 * ( Double.parseDouble( in ) ) * 12 + Double.parseDouble( ft ) )
                     - ( 4.6756 * Double.parseDouble( age ) ) )  * 1.2);
             BigDecimal bd = BigDecimal.valueOf(answer);
             bd = bd.setScale(2, BigDecimal.ROUND_FLOOR);
             etanswer.setText(bd.toString());  
        }
        else if (spinnerText.equals("Lightly Active")){
            //actAnswer = "1.375";
             answer =  ( ( 665 + ( 4.3379 * Double.parseDouble( weight ) ) + 
                     ( 4.6980 * ( Double.parseDouble( in ) ) * 12 + Double.parseDouble( ft ) )
                     - ( 4.6756 * Double.parseDouble( age ) ) )  * 1.375);
             BigDecimal bd = BigDecimal.valueOf(answer);
             bd = bd.setScale(2, BigDecimal.ROUND_FLOOR);
             etanswer.setText(bd.toString());  
        }
        else if (spinnerText.equals("Moderately Active")){
            // actAnswer = "1.55";
             answer =  ( ( 665 + ( 4.3379 * Double.parseDouble( weight ) ) + 
                     ( 4.6980 * ( Double.parseDouble( in ) ) * 12 + Double.parseDouble( ft ) )
                     - ( 4.6756 * Double.parseDouble( age ) ) )  * 1.55);
             BigDecimal bd = BigDecimal.valueOf(answer);
             bd = bd.setScale(2, BigDecimal.ROUND_FLOOR);
             etanswer.setText(bd.toString());  
        }
        else if (spinnerText.equals("Heavily Active")){
            // actAnswer = "1.725";
             answer =  ( ( 665 + ( 4.3379 * Double.parseDouble( weight ) ) + 
                     ( 4.6980 * ( Double.parseDouble( in ) ) * 12 + Double.parseDouble( ft ) )
                     - ( 4.6756 * Double.parseDouble( age ) ) )  * 1.725);
             BigDecimal bd = BigDecimal.valueOf(answer);
             bd = bd.setScale(2, BigDecimal.ROUND_FLOOR);
             etanswer.setText(bd.toString());  
        }


     // call for custom toast
     viewBMRSavedToast();
    }

} // end of calculateWomen method

如果您发现有任何问题,请通知我。谢谢。会很感激的。

4

2 回答 2

3

你可以使用这个方法:

spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
    public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
        String selected = parent.getItemAtPosition(pos).toString();
    }
    public void onNothingSelected(AdapterView<?> parent) {
    }
});
于 2012-09-01T14:37:39.947 回答
0

如果您在选择项目时想要微调器值,那么您应该在编码中使用微调器 onitemselected 侦听器。< Android Spinner:获取选定的项目更改事件> 此链接将进一步帮助您。

于 2012-09-01T14:27:26.777 回答