Skip to content
Davide Steduto edited this page Jul 22, 2016 · 15 revisions

In this page

  • XML Configuration
  • Java initialization
  • Callbacks
  • Customization

XML Configuration

FastScroller needs an XML layout and Java initialization. The layout has to be placed at the end of the view hierarchy after everything else has been declared:

	...
	<android.support.v7.widget.RecyclerView
		.../>
	...
	<!-- FastScroller Layout must be at the end of ViewHierarchy
		 in order to be displayed at the top of every views -->
	<include layout="@layout/fast_scroller"/>

</FrameLayout>

Here is the layout/fast_scroller.xml

<eu.davidea.fastscroller.FastScroller
	xmlns:android="http://schemas.android.com/apk/res/android"
	xmlns:tools="http://schemas.android.com/tools"
	android:id="@+id/fast_scroller"
	android:layout_width="wrap_content"
	android:layout_height="match_parent"
	android:layout_centerHorizontal="true"
	android:layout_alignTop="@+id/swipeRefreshLayout"
	android:layout_alignBottom="@+id/swipeRefreshLayout"
	android:layout_alignParentEnd="true"
	android:layout_alignParentRight="true"
	android:visibility="gone"
	tools:visibility="visible"/>

Java initialization

In the creation of the Activity/Fragment call setFastScroller() after the Adapter has been attached to the RV:

//First, assign the Adapter to the RV
mRecyclerView.setAdapter(mAdapter);
//Add FastScroll to the RecyclerView
//stateChangeListener is optional and might be the Activity
mAdapter.setFastScroller((FastScroller) findViewById(R.id.fast_scroller),
		Utils.getColorAccent(context)[, stateChangeListener]);

Callbacks

A useful callback is triggered when the handle is draggeded, the method onFastScrollerStateChange() is called.
From the Activity, implement the callback method:

@Override
public void onFastScrollerStateChange(boolean scrolling) {
	//Example
	if (scrolling) hideFab();
	else showFab();
}

The text is built from the Adapter callback. It has to be implemented/overridden from the inside of a CustomAdapter that extends FlexibleAdapter:

@Override
public String onCreateBubbleText(int position) {
	IFlexible iFlexible = getItem(position);
	return iFlexible.toString().substring(0,1).toUpperCase();
}

Customization

The following 3 methods give full control on the FastScroller instance:

/**
 * Changes the visibility of the View
 */
public void toggleFastScroller();

/**
 * Returns true, if FastScroller is configured and shown, false otherwise
 */
public boolean isFastScrollerEnabled();

/**
 * Returns the FastScroller instance for more control on the settings.
 */
public FastScroller getFastScroller();

FastScroller is composed by:

Note: The Resources can be overridden by assigning the same @+id to the views of the base layout.
The previous Drawables and XML create the following preview:

FastScroller

Clone this wiki locally