@ NonNull private RecyclerView . AdapterDataObserver createAdapterDataObserver ( ) { return new RecyclerView . AdapterDataObserver ( ) { @ Override public void onChanged ( ) { super . onChanged ( ) ; updateNavigationPreferences ( ) ; } @ Override public void onItemRangeChanged ( final int positionStart , final int itemCount ) { super . onItemRangeChanged ( positionStart , itemCount ) ; updateNavigationPreferences ( ) ; } @ Override public void onItemRangeChanged ( final int positionStart , final int itemCount , @ Nullable final Object payload ) { super . onItemRangeChanged ( positionStart , itemCount , payload ) ; updateNavigationPreferences ( ) ; } @ Override public void onItemRangeInserted ( final int positionStart , final int itemCount ) { super . onItemRangeInserted ( positionStart , itemCount ) ; updateNavigationPreferences ( ) ; } @ Override public void onItemRangeRemoved ( final int positionStart , final int itemCount ) { super . onItemRangeRemoved ( positionStart , itemCount ) ; updateNavigationPreferences ( ) ; } @ Override public void onItemRangeMoved ( final int fromPosition , final int toPosition , final int itemCount ) { super . onItemRangeMoved ( fromPosition , toPosition , itemCount ) ; updateNavigationPreferences ( ) ; } } ; }
Creates and returns a data observer which allows to adapt the navigation preferences when the adapter s underlying data has been changed .