I have been asked to make a program on android which is able to convert from Fahrenheit to celcius degrees and vice versa, up to here all easy, but, I wonder if it is possible to do that by putting 1 for example in Celcius degrees I present myself automatically its corresponding value in degrees Fahrenheit. Is there any way to do it?
This is my logical code for my application, which I need to give Enter to calculate the equivalence
public class MainActivity extends AppCompatActivity {
private EditText f,c;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
f = (EditText)findViewById(R.id.et_f);
c = (EditText)findViewById(R.id.et_c);
c.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
Double gf = ((1.8)*Double.parseDouble(c.getText().toString()))+32;
f.setText(""+gf);
return false;
}
});
f.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
Double gc = (Double.parseDouble(f.getText().toString())-32)/1.8;
c.setText(""+gc);
return false;
}
});
}
}