私Spinner
のString
Array
場合、{座りがちで、軽く活動的で、中程度に活動的で、非常に活動的} (これは BMR の計算です)
私がやりたいのは、選択したアイテムをSpinner
.
たとえば、sedentaryをクリックすると、sedentaryの値が1.2であるため、bmrの結果はmultiplied
by 1.2になります。しかし、私はそれをうまく機能させることができないようです。
以下の私のコードを確認してください:
private void calculateMen(){
String f1 = etft.getText().toString();
String f2 = etin.getText().toString();
String f3 = etweight.getText().toString();
String f4 = etage.getText().toString();
if ( (f1.isEmpty() || f2.isEmpty() || f3.isEmpty() || f4.isEmpty() ) )
{ // call for custom toast
viewErrorToast();
}
else
{
// Metric Formula for BMR (Men) English Unit
// 66 + ( 6.2377 x weight in kilos ) +
//( 12.7084 x height in cm ) - ( 6.7550 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"))
{
answer = ( ( 66 + ( 6.2377 * Double.parseDouble( weight ) ) + ( 12.7084 * ( Double.parseDouble( in ) * 12 + Double.parseDouble( ft ) ) ) - ( 6.8 * Double.parseDouble( age ) ) ) * 1.2 );
//* Double.parseDouble(actAnswer) ;
BigDecimal bd = BigDecimal.valueOf(answer);
bd = bd.setScale(2, BigDecimal.ROUND_FLOOR);
etanswer.setText(bd.toString());
}
else if (spinnerText.equals("Lightly Active"))
{
answer = ( ( 66 + ( 6.2377 * Double.parseDouble( weight ) ) + ( 12.7084 * ( Double.parseDouble( in ) * 12 + Double.parseDouble( ft ) ) ) - ( 6.8 * Double.parseDouble( age ) ) ) * 1.375 );
//* Double.parseDouble(actAnswer) ;
BigDecimal bd = BigDecimal.valueOf(answer);
bd = bd.setScale(2, BigDecimal.ROUND_FLOOR);
etanswer.setText(bd.toString());
}
else if (spinnerText.equals("Moderately Active"))
{
answer = ( ( 66 + ( 6.2377 * Double.parseDouble( weight ) ) + ( 12.7084 * ( Double.parseDouble( in ) * 12 + Double.parseDouble( ft ) ) ) - ( 6.8 * Double.parseDouble( age ) ) ) * 1.55 );
//* Double.parseDouble(actAnswer) ;
BigDecimal bd = BigDecimal.valueOf(answer);
bd = bd.setScale(2, BigDecimal.ROUND_FLOOR);
etanswer.setText(bd.toString());
}
else if (spinnerText.equals("Heavily Active"))
{
answer = ( ( 66 + ( 6.2377 * Double.parseDouble( weight ) ) + ( 12.7084 * ( Double.parseDouble( in ) * 12 + Double.parseDouble( ft ) ) ) - ( 6.8 * Double.parseDouble( age ) ) ) * 1.725 );
//* Double.parseDouble(actAnswer) ;
BigDecimal bd = BigDecimal.valueOf(answer);
bd = bd.setScale(2, BigDecimal.ROUND_FLOOR);
etanswer.setText(bd.toString());
}
// call for custom toast
viewBMRSavedToast();
}
} // end of calculateMen method