The RecyclerView
, unlike to ListView
, doesn\'t have a simple way to set an empty view to it, so one has to manage it manually, making empty view vi
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.