Android微调器值未显示结果

时间:2012-09-01 14:16:51

标签: android

我正在尝试计算女性的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

如果您发现任何错误,请通知我。谢谢。我会很感激的。

2 个答案:

答案 0 :(得分: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) {
    }
});

答案 1 :(得分:0)

如果在选择项目时是否需要微调器值,则应在编码内使用微调器onitemselected listener。 &LT; Android Spinner: Get the selected item change event&gt;这个链接将进一步帮助你。