Problem with EditText TextChangeListener

I have an edit text designed for search. I added

searchET.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // 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 afterTextChanged(Editable s) { // TODO Auto-generated method stub //intent to another page where i show my search result } }); 

The problem is this: When I give a search string, for example: "fort", I get the desired result on the next page. But when I click the back button, it does not move to the previous page on the first click. I will have to press the button 4 times to go to the previous page. This is because my search string is 4 in length and each time a value is entered into edittext, a textchangelistener is called. How can I solve this problem? Answer please. Thanks in advance.

+4
source share
2 answers

Depending on what you need, you can go to the next page based on some conditions. For example, start the timer, and if the afterTextChanged call afterTextChanged called before the timer expires, reset the timer. In addition, you may have a “Search” button, where the user explicitly indicates that he typed a word.

If you can share the desired behavior, you can suggest better alternatives.

+2
source

in fact, when you want to decide when the text ends, it makes no sense to include addTextChangedListener. To improve the user interface, you can add this button to the ur.refer: edittext edit text with a view

0
source

Source: https://habr.com/ru/post/1345825/


All Articles