FastScroll icon indicating copy to clipboard operation
FastScroll copied to clipboard

RecyclerView shows handle when Filterable returns an empty list

Open jacopotediosi opened this issue 2 years ago • 0 comments

Behavior similar to #5, the handle is shown when the adapter implements Filterable and the search filter returns an empty dataset. As a bonus, this caused my app to crash when touching the handle in that situation, because my implementation of the getSectionText() method, calling .get() on an empty list, threw an ArrayIndexOutOfBoundsException.

I fixed implementing the following code in my class, but in my opinion this should be managed by the Fastscroller itself:

public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        MyClassBinding binding = MyClassBinding.inflate(getLayoutInflater());
        FastScrollRecyclerView recyclerView = binding.recyclerView;
        
        [... myAdapter initialization ...]

        myAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
                @Override public void onChanged() {
                        super.onChanged();
                        recyclerView.setFastScrollEnabled(myAdapter.getItemCount() != 0);
                }
        });

        [...]

        return binding.getRoot();
}

jacopotediosi avatar Apr 18 '23 09:04 jacopotediosi