Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is an own RecyclerView really needed? #4

Closed
Rainer-Lang opened this issue Oct 26, 2016 · 5 comments
Closed

Is an own RecyclerView really needed? #4

Rainer-Lang opened this issue Oct 26, 2016 · 5 comments

Comments

@Rainer-Lang
Copy link

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

@randr0id
Copy link
Member

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
Copy link
Author

Oh great!
May I ask for an example?

@randr0id
Copy link
Member

randr0id commented Oct 28, 2016

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
Copy link
Author

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

@igozhenko
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants