2015-06-19 2 views
0

Не работает. Вот код для моей деятельности. Все ли написано? causez значение результата не работает в if if statement !!Как сравнить это двойное значение, чтобы найти результат?

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); 
    } 
} 
+1

какой результат вы становитесь в сообщении Toast? Я имею в виду, каково значение переменной «result» после математических операций? –

+0

Он не показывает .. его давая ошибку, которая не может быть показана в Toast –

ответ

0

пытаются преобразовать все значения в двойной, а не некоторые из них, чтобы быть Float и другие, чтобы быть двойной и выполните следующие действия:

double h,w, result; 

h = Double.parseDouble(height.getText().toString()); 
w = Double.parseDouble(weight.getText().toString());