In this code I have search multiple text ex. I have search sachin.
sachin is show the list but click to back sachin to sac not display to sa list on adapter. How to solve it without any library?
when I press back space and remove a char this time dos not list not display.
Example
Suppose I have search sachin to text change sachin to sac. In this case not display sa list. I have clear all list that case display all list.
search sa show the list
sachin and sardar
now search sac
now display the sachin
search only sac to sc
that's time display only sachin
not disply the sardar in the list
My Adapter
private class ItemFilter extends Filter {
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults results = new FilterResults();
if (constraint != null && constraint.length() > 0) {
ArrayList<Build> buildlist = new ArrayList<Build>();
for (int i = 0; i < buildList.size(); i++) {
if ((buildList.get(i).getName().toUpperCase())
.contains(constraint.toString().toUpperCase())) {
Build babydata = new Build(buildList.get(i).getImages(), buildList.get(i).getName());
buildlist.add(babydata);
}
}
results.count = buildlist.size();
results.values = buildlist;
} else {
results.count = buildList.size();
results.values = buildList;
}
return results;
}
@Override
protected void publishResults(CharSequence constraint,
FilterResults results) {
buildList = (ArrayList<Build>) results.values;
notifyDataSetChanged();
}
}
Activity class
EditText editTxt = (EditText) findViewById(R.id.search);
editTxt.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (s.length() <= 0) {
Log.d("jay", "s.length() <= 0" + s.toString());
buildList.clear();
buildList.addAll(buildListCopy);
recyclerView.setAdapter(null);
buildCustomAdapter = new BuildCustomAdapter(buildList);
recyclerView.setAdapter(buildCustomAdapter);
} else {
buildCustomAdapter.getFilter().filter(s.toString());
}
Log.d("jay", "mobisharnam" + s.toString());
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
});