Vote count:
0
I have looked at some other questions and posts, but I can't seem to figure this out... I am building a conversion app, I am able to auto populate Feet and Yards by putting the inches in, using addTextChangedListener, but I cant figure out how to addTextChangedListener to the other fields so that I can enter Feet and automatically convert to Inches and Yards, and Yards to Inches and Feet...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText editIn = (EditText) findViewById(R.id.editIn);
final EditText editFt = (EditText) findViewById(R.id.editFt);
final EditText editYd = (EditText) findViewById(R.id.editYd);
editIn.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { }
@Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
try {
double in = Double.valueOf(editIn.getText().toString());
double ft = in / 12;
double yd = in / 36;
editFt.setText(String.valueOf(ft));
editYd.setText(String.valueOf(yd));
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
@Override
public void afterTextChanged(Editable editable) { }
asked 50 secs ago
Aucun commentaire:
Enregistrer un commentaire