I have two edittext
's amount and percentage. When I type amount in edittext
percentage edittext
should change and vice versa. How to achieve this?
Asked
Active
Viewed 30 times
-2

Maharsh
- 53
- 5
-
You use a TextWatcher on both edit texts. You'll need to code carefully to avoid infinite looping the two though. – Gabe Sechan Sep 14 '18 at 06:30
-
@GabeSechan any examples. does this work [https://stackoverflow.com/questions/7117209/how-to-know-key-presses-in-edittext] – Maharsh Sep 14 '18 at 06:30
-
Can you edit your question to show what you've tried – John M Sep 14 '18 at 07:13
1 Answers
0
This is how you can achieve it.
EditText percentage = (EditText)findViewById(R.id.percentage);
EditText amount = (EditText)findViewById(R.id.amount);
amount.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
// calculate percentage and set it to percentage here
}
@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) {
}
});

SRB Bans
- 3,096
- 1
- 10
- 21
-
In that case only one `edittext` will work other will not work. try it you want – Maharsh Sep 14 '18 at 06:57