Skip to content

Instantly share code, notes, and snippets.

@haidong94
Created February 28, 2018 02:28
Show Gist options
  • Save haidong94/e6e2b0849e0441fcc303f6b9852d3f8f to your computer and use it in GitHub Desktop.
Save haidong94/e6e2b0849e0441fcc303f6b9852d3f8f to your computer and use it in GitHub Desktop.
@Override
public boolean onQueryTextChange(String newText) {
adapter.getFilter().filter(newText);
adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
@Override
public void onChanged() {
super.onChanged();
checkEmpty();
}
@Override
public void onItemRangeInserted(int positionStart, int itemCount) {
super.onItemRangeInserted(positionStart, itemCount);
checkEmpty();
}
@Override
public void onItemRangeRemoved(int positionStart, int itemCount) {
super.onItemRangeRemoved(positionStart, itemCount);
checkEmpty();
}
void checkEmpty() {
recyclerView.setVisibility(adapter.getItemCount() == 0 ? View.GONE : View.VISIBLE);
}
});
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment