Skip to content
Davide Steduto edited this page Oct 25, 2017 · 14 revisions

In this page


Main exposed listeners

Usually, an Activity or Fragment can be an instance of multiple listeners. Optionally, a listener can be an object of your preference. All you need to do is to pass the listener object to the Constructor of the FlexibleAdapter OR to call the function addListener(listener) for ALL types of listeners.

OnUpdateListener

Callback dedicated, mainly but not only, to update the emptyView of your design.

OnDeleteCompleteListener

UndoHelper will invoke this callback to confirm the items deletion after the timeout foreseen.

OnItemClickListener

Activated when user taps an item, this callback is registered on the itemView and propagated until the implementation through the Adapter where it resides.

OnItemLongClickListener

Activated when user long press an item. Same concept of click listener.

OnActionStateListener

Triggered by ItemTouchHelperCallback, when the view changes state from being dragged, swiped and released by the user (end of a "drop" and "swipe" events).

OnItemMoveListener

Triggered by ItemTouchHelperCallback when an item has been dragged far enough to trigger a move. This is called every time an item is shifted, and not at the end of a "drop" event.

OnItemSwipeListener

Triggered by ItemTouchHelperCallback when an item has been dismissed by a swipe.

OnStickyHeaderChangeListener

Called by StickyHeaderHelper when a sticky header has been swapped or cleared out.

Listener exposed through methods

EndlessScrollListener

This callback is registered through the method setEndlessScrollListener() instead of via addListener(), because the endless scroll works also without this callback, for instance, when the loading more is asked to the user which confirm it through a button, in this case should not be automatic.

Overridden listeners

The FlexibleAdapter and the FlexibleViewHolder implement some callback in order to provide specific features. You can of course override the exposed methods.

BubbleTextCreator

Provides basic implementation to display the current position in the bubble text of the FastScroller.

OnScrollStateChangeListener

Provides info to AnimatorAdapter to stop animating items if FastScroller is currently active.

AdapterCallback

Internal interface for Adapter to listen for a move or swipe dismissal event from ItemTouchHelperCallback.

ViewHolderCallback

Internal Interface for ViewHolder to notify of relevant callbacks. This listener, is to intend as a further way to display how a ViewHolder will display the middle and final activation state. Generally the final action should be handled by the listeners OnItemMoveListener and OnItemSwipeListener.

Others listeners

The list of listeners is not finished :-)
There are more listeners that are covered in the dedicated pages for the ActionModeHelper and UndoHelper. However, here we just mention them:

  • Android ActionMode.Callback
  • UndoHelper listeners
    • onActionCanceled
    • onActionConfirmed

Custom listeners

Follow these steps:

  1. Override FlexibleAdapter with your own CustomAdapter and create a public field for the Callback interface that can be used in the ViewHolder. From now on, you will instantiate only CustomAdapter.
  2. The constructor of the CustomAdapter accepts the implementation of the callback.
  3. The constructor of the ViewHolder accept your CustomAdapter instead of FlexibleAdapter so when you create the ViewHolder you cast the Adapter to CustomAdapter.
  4. Inside the click listener of your button/image you can call the callback interface: mAdapter.MyCallback, where mAdapter is a private field in the ViewHolder initialized in the constructor.
  5. The implementation of the callback can finally be done in the Activity / Fragment as a field or as implementation of the class itself.

Clone this wiki locally