Design + Code an Android App from Scratch
This video shows how to use RecyclerView.AdapterDataObserver to be notified of changes in the RecyclerView’s items so that we can hide the RecyclerView and the Toolbar when there are no items to display. In the first step, we make a custom RecyclerView in code. In the second step, we create an anonymous class that extends AdapterDataObserver and override its methods onChanged, onItemRangeInserted, onItemRangeChanged, onItemRangeMoved and onItemRangeRemoved. Next, we override the setAdapter method of the custom RecyclerView and call registerAdapterDataObserver to register the anonymous class with our RecyclerView. In the next step we simply toggle the Views using the setVisibility method to show or hide them based on the number of items inside our RecyclerView.