I use addTextChangedListener to search item from server with retrofit. but only android version 10 onTextChanged count not working...?
Here is my code
searchEdit.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (count>1) {
String name = searchEdit.getText().toString().trim();
if (!name.isEmpty()) {
searchItemByName(name);
}
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
I'll go with the assumption that you're using
countparameter inonTextChangedcallback as the number of characters inside yoursearchEditEdittext.Solution: You need to use
s.length()function instead of the parametercount, like this:Explanation:
If you have a look at the documentation of
android.text.TextWatcher::onTextChangedfunction below:it says that
countparameter refers to the number of characters changed ins, and thus, if you're typing into the edittext youronTextChangedfunction will be called with the parametercountis 1.Alternatively: you can use
afterTextChangedcallback withs.length().