L4Digital / FastScroll

A ListView-like FastScroller for Android’s RecyclerView.
Apache License 2.0
901 stars 75 forks source link

Is an own RecyclerView really needed? #4

Closed Rainer-Lang closed 7 years ago

Rainer-Lang commented 7 years ago

Have a look here: https://github.com/turing-tech/MaterialScrollBar

randr0id commented 7 years ago

No, it is not required. You can add the FastScroller view to your layout with a RecyclerView and set it up manually. Creating a class that extends RecyclerView made the implementation simpler.

Rainer-Lang commented 7 years ago

Oh great! May I ask for an example?

randr0id commented 7 years ago

Using the included example:

private FastScroller fastScroller;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ExampleAdapter adapter = new ExampleAdapter();

    RecyclerView recyclerView = findViewById(R.id.recycler_view);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setAdapter(adapter);

    fastScroller = findViewById(R.id.fast_scroller);
    fastScroller.setSectionIndexer(adapter);
    fastScroller.attachRecyclerView(recyclerView);
}

@Override
protected void onDestroy() {
    fastScroller.detachRecyclerView();
    super.onDestroy();
}

private static class ExampleAdapter extends RecyclerView.Adapter<ExampleAdapter.ViewHolder> implements FastScroller.SectionIndexer {

    ...

    @Override
    public String getSectionText(int position) {
        return String.valueOf(mItemList.get(position).charAt(0));
    }
}
<android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

<com.l4digital.fastscroll.FastScroller
    android:id="@+id/fast_scroller"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="end"
    app:bubbleColor="@color/fastscroll_bubble"
    app:bubbleTextColor="@color/fastscroll_text"
    app:handleColor="@color/fastscroll_handle" />
Rainer-Lang commented 7 years ago

@randr0id Thanks a lot. I'll try it in the next days.

igozhenko commented 7 years ago

@randr0id I guess, you need to add this way into readme