1 Replies - 599 Views - Last Post: 28 June 2019 - 07:57 AM

#1 markonioni   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 21-March 19

Not showing empty state when filtered results are 0 in recycler view

Posted 21 June 2019 - 09:45 AM

I got this searchView which I use to filter recyclerView. So when there is no results for some search query, I want to show textView to user by setting its visibility to VISIBLE. So in searchView listener, I do:

@Override
            public boolean onQueryTextChange(String s) {
                adapter.getFilter().filter(s);

                if (adapter.getItemCount()<=0){
                    emptyStateConatiner.setVisibility(View.VISIBLE);
                }
                else  emptyStateConatiner.setVisibility(View.GONE);

                return false;
            }

But this doesn't work as I would expect, because when I type non existing search query, it first shows empty recyclerView and only after that, if I type additional letter to that query, I get emptyStateContainer shown.

Does anyone know what is causing this behavior?

Is This A Good Question/Topic? 0
  • +

Replies To: Not showing empty state when filtered results are 0 in recycler view

#2 TechnoBear   User is offline

  • Lady A
  • member icon

Reputation: 462
  • View blog
  • Posts: 1,398
  • Joined: 02-November 11

Re: Not showing empty state when filtered results are 0 in recycler view

Posted 28 June 2019 - 07:57 AM

onQueryTextChange is what is causing the behavior.

At the time you type the non-existing query the adapter has items, thus at the current time that the text is changing, there are items present. After executing the query, there are no items but the text is not changing in the control. Now that the adapter has no items, if you change the text, your view will appear.

Better to perform this check when populating the adapter.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1