this.Searchtext = (EditText) findViewById(R.id.search_input);
this.Searchtext.addTextChangedListener(new TextWatcher() {
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
public void afterTextChanged(Editable editable) {
MainActivity.this.filterQuery(editable.toString());
}
});
public void filterQuery(String text) {
ArrayList<ExampleItem> filterdNames = new ArrayList<>();
for (ExampleItem s : this.exampleList) {
if (s.getText1().toLowerCase().contains(text) || s.getText2().toLowerCase().contains(text)) {
filterdNames.add(s);
}
}
this.adapter.setFilter(filterdNames);
}
public void setFilter(List<ExampleItem> filterdNames) {
this.exampleList = filterdNames;
notifyDataSetChanged();
}