Android 12 Developer Preview is here! Try it out, and give us your feedback!


class Builder<K : Any!>
   ↳ androidx.recyclerview.selection.SelectionTracker.Builder

Builder is the primary mechanism for create a SelectionTracker that can be used with your RecyclerView. Once installed, users will be able to create and manipulate selection using a variety of intuitive techniques like tap, gesture, and mouse lasso.

Example usage:

  tracker = new SelectionTracker.Builder&lt;&gt;(
             new DemoStableIdProvider(recyclerView.getAdapter()),
             new MyDetailsLookup(recyclerView),

Restricting which items can be selected and limiting selection size

SelectionPredicate provides a mechanism to restrict which Items can be selected, to limit the number of items that can be selected, as well as allowing the selection code to be placed into "single select" mode, which as the name indicates, constrains the selection size to a single item.

Configuring the tracker for single single selection support can be done by supplying SelectionPredicates#createSelectSingleAnything(). SelectionTracker tracker = new SelectionTracker.Builder<>( "my-string-selection", recyclerView, new DemoStableIdProvider(recyclerView.getAdapter()), new MyDetailsLookup(recyclerView), StorageStrategy.createStringStorage()) .withSelectionPredicate(SelectionPredicates#createSelectSingleAnything()) .build();

Retaining state across Android lifecycle events

Support for storage/persistence of selection must be configured and invoked manually owing to its reliance on Activity lifecycle events. Failure to include support for selection storage will result in the active selection being lost when the Activity receives a configuration change (e.g. rotation) or when the application process is destroyed by the OS to reclaim resources.

Key Type

Developers must decide on the key type used to identify selected items. Support is provided for three types: Parcelable, String, and Long.

Parcelable: Any Parcelable type can be used as the selection key. This is especially useful in conjunction with as the Android URI implementation is both parcelable and makes for a natural stable selection key for values represented by the Android Content Provider framework. If items in your view are associated with stable content:// uris, you should use Uri for your key type.

String: Use String when a string based stable identifier is available.

Long: Use Long when RecyclerView's long stable ids are already in use. It comes with some limitations, however, as access to stable ids at runtime is limited. Band selection support is not available when using the default long key storage implementation. See StableIdKeyProvider for details.


private SelectionTracker<uri>
      public void onCreate(Bundle savedInstanceState) {
      // See above for details on constructing a SelectionTracker instance.
      if (savedInstanceState != null) {
      protected void onSaveInstanceState(Bundle outState) {


Public constructors
<init>(@NonNull selectionId: String, @NonNull recyclerView: RecyclerView, @NonNull keyProvider: ItemKeyProvider<K>, @NonNull detailsLookup: ItemDetailsLookup<K>, @NonNull storage: StorageStrategy<K>)

Creates a new SelectionTracker.

Public methods

Prepares and returns a SelectionTracker.

withBandOverlay(@DrawableRes bandOverlayId: Int)

Replaces default band overlay.

withBandPredicate(@NonNull bandPredicate: BandPredicate)

Replaces default band predicate.

withFocusDelegate(@NonNull delegate: FocusDelegate<K>)

Add focus delegate to interact with selection related focus changes.

withGestureTooltypes(@NonNull vararg toolTypes: Int)

Replaces default tap and gesture tool-types.


Adds a context click listener.


Adds a drag initiated listener.


Adds an item activation listener.


Add operation monitor allowing access to information about active operations (like band selection and gesture selection).

withPointerTooltypes(@NonNull vararg toolTypes: Int)

Replaces default pointer tool-types.


Install selection predicate.

Public constructors


    @NonNull selectionId: String,
    @NonNull recyclerView: RecyclerView,
    @NonNull keyProvider: ItemKeyProvider<K>,