Search View shows blank after entering a space.
Duplicate question - click , but using recycler view doesn't suit me. Are there other options.
I will be very glad if you help!
I am filtering now:
mySearchView.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) {
}
@Override
public void afterTextChanged(Editable s) {
adapter.getFilter().filter(s);
}
});
CodePudding user response:
public static void main(String[] args) {
// Creating a list of Integers
List<Integer> list = Arrays.asList(3, 4, 6, 12, 20);
// Getting a stream consisting of the
// elements that are divisible by 5
// Using Stream filter(Predicate predicate)
list.stream()
.filter(num -> num % 5 == 0)
.forEach(System.out::println);
}
CodePudding user response:
You must write your code in onTextChanged.
mySearchView.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) {
adapter.getFilter().filter(s);
}
@Override
public void afterTextChanged(Editable s) {
}
});