Applying TextWatcher on multiple edit text
Im trying to apply effect on 2 edit text fields by text watcher..i.e Data
entered in one text field is posted in the others by performing operation.
The problem is that it works fine with the one edit text i.e the data in
first is posted in other fields but as soon as i try to perform this in
2nd text field it stops unexpectedly..I've tried almost anything ..the
recent way that Im using runs successfully but doesn't apply the formula
inside..The code is big but I'll paste it..Plz help..Thanks in advance..
sec=(EditText) findViewById(R.id.seconds); millisec=(EditText)
findViewById(R.id.milliseconds);
min=(EditText) findViewById(R.id.minutes);
if (sec.isFocused()){
sec.addTextChangedListener(new TextWatcher(){
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int
after) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int
count) {
double min12,min22;
try{
String minute = sec.getText().toString();
min12 = Double.parseDouble(minute);
min12=min12*60;
min22=12*13;
min.setText(Double.toString(min12));
millisec.setText(Double.toString(min22));
} catch(NumberFormatException e){
min.setText("");
millisec.setText("");
}
else if (min.isFocused()){
min.addTextChangedListener(new TextWatcher(){
public void onTextChanged(CharSequence s, int start, int before, int count) {
try{
String minute = min.getText().toString();
min1 = Double.parseDouble(minute);
min1=min1*60;
min2=min1*1000;
sec.setText(Double.toString(min1));
millisec.setText(Double.toString(min2));
} catch(NumberFormatException e){
sec.setText("");
millisec.setText("");
}
}
}); };
No comments:
Post a Comment