Android findView of Linearlayout and set background in recycleradapter

First of all, I recommend migrating from findViewById() to viewBindng to prevent app from crashing in running time. Second, You can only access views inside recyclerView’s items from adapter. to implement what you want, you should listen for recyclerView’s adapter change. You can use AdapterDataObserver:

adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
        public void onItemRangeRemoved(int positionStart, int itemCount) {
            super.onItemRangeRemoved(positionStart, itemCount);

Take a look at this link in android documentation.

Another way to achieve that will be checking for adapter’s item count everytime you remove an element:


if(adapter.getItemCount() == 0)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top