[英]How to compare a double value to a decimal from database and if they are alike, then return true
[英]How to compare this double value to find the result?
它不起作用。 這是我的活動的代碼。 全部寫完了嗎? Causez結果的值在if else語句中不起作用!
package com.android.don.myapplication;
public class mapActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
}
public void checkButtonClicked(View view)
{
RadioButton maleRadioButton, femaleRadioButton;
EditText height = (EditText)findViewById(R.id.editText);
EditText weight = (EditText)findViewById(R.id.editText2);
TextView show = (TextView) findViewById(R.id.resultView);
float h,w;
double result;
maleRadioButton = (RadioButton) findViewById(R.id.maleRadio);
femaleRadioButton = (RadioButton) findViewById(R.id.femaleRadio);
if (maleRadioButton.isChecked()) {
h = Float.parseFloat(height.getText().toString());
w = Float.parseFloat(weight.getText().toString());
result = (h/((w*0.025)*(w*0.025)));
Toast.makeText(mapActivity.this,"Answer is "+result,Toast.LENGTH_LONG);
if (result < 18.500) {
show.setText("UW");
}
else if (result < 25.000) {
show.setText("NM");
} else if (result < 30.000) {
show.setText("OW");
}
else if (result>30.000){
show.setText("VVM");
}
}
else if (femaleRadioButton.isChecked())
{
h = Float.parseFloat(height.getText().toString());
w = Float.parseFloat(weight.getText().toString());
result = (h/((w*0.025)*(w*0.025)));
//Toast.setText(mapActivity.this,"Value of a: " + String.valueOf(result),Toast.LENGTH_LONG);
if (result < 16.500) {
show.setText("UW");
}
else if (result < 22.000) {
show.setText("NM");
} else if (result < 27.000) {
show.setText("OW");
} else if (result>30.000){
show.setText("VVM");
}
}
else {
Toast.makeText(getApplicationContext(), "Select A Gender", Toast.LENGTH_SHORT).show();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_map, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
嘗試將所有值轉換為Double,而不是將其中一些轉換為Float,將其他值轉換為Double,然后執行以下操作:
double h,w, result;
h = Double.parseDouble(height.getText().toString());
w = Double.parseDouble(weight.getText().toString());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.