Here's my code: It only works when i convert it from Fahrenheit to Celcius but it doesn't work when i convert it from Celcius into Fahrenheit. I've tried for so many times but it still doesn't work for me.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.converter_second);
rb_celcius = (RadioButton) findViewById(R.id.radioButton_celcius);
rb_fahrenheit = (RadioButton) findViewById(R.id.radioButton2_fahrenheit);
btn_convert = (Button) findViewById(R.id.button3_convert);
btn_clear = (Button) findViewById(R.id.button5_clear);
edTxt_amount = (EditText) findViewById(R.id.editText_amount);
txtVw_answer = (TextView) findViewById(R.id.textView7_answer);
btn_convert.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
double dblFahrenheit = 0;
double dblCelcius = (5.0 / 9) * (dblFahrenheit - 32);
double dblConvertedTemp = 0;
double dblFahConversion;
if (v == btn_convert) {
if (rb_celcius.isChecked()) {
String strFah = edTxt_amount.getText().toString();
if (!strFah.isEmpty()) {
{
dblFahrenheit = Double.parseDouble(strFah);
}
if (dblFahrenheit <= 212) {
dblConvertedTemp = (5.0 / 9.0) * (dblFahrenheit - 32);
txtVw_answer.setText("The answer is " + dblConvertedTemp);
} if (rb_fahrenheit.isChecked()) {
String strCel = edTxt_amount.getText().toString();
if (!strCel.isEmpty()) {
{
dblCelcius = Double.parseDouble(strCel);
}
if (dblCelcius <= 100) {
dblFahConversion = dblCelcius * (9.0 / 5.0) + 32;
txtVw_answer.setText("The answer is" + dblFahConversion);
}
}
else if (v == btn_clear){
rg_group.clearCheck();
txtVw_answer.setText("");
}
}
}
}
}
}
});
}
}
Aucun commentaire:
Enregistrer un commentaire