Skip to content

RecyclerView shows handle when Filterable returns an empty list #89

@jacopotediosi

Description

@jacopotediosi

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();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions