Detect animation finish in Android’s RecyclerView

Currently the only working way I’ve found to solve this problem is to extend ItemAnimator and pass it to RecyclerView like this:

recyclerView.setItemAnimator(new DefaultItemAnimator() {
    @Override
    public void onAnimationFinished(RecyclerView.ViewHolder viewHolder) {
        updateEmptyView();
    }
});

But this technique is not universal, because I have to extend from concrete ItemAnimator implementation being used by RecyclerView. In case of private inner CoolItemAnimator inside CoolRecyclerView, my method will not work at all.


PS: My colleague suggested to wrap ItemAnimator inside the decorator in a following manner:

recyclerView.setItemAnimator(new ListenableItemAnimator(recyclerView.getItemAnimator()));

It would be nice, despite seems like overkill for a such trivial task, but creating the decorator in this case is not possible anyway, because ItemAnimator has a method setListener() which is package protected so I obviously can’t wrap it, as well as several final methods.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)