remove RecyclerView HeaderView - Android User Interface

Android examples for User Interface:RecyclerView

Description

remove RecyclerView HeaderView

Demo Code


import android.support.v7.widget.RecyclerView;
import android.view.View;

public class Main{
    /*  w w  w .j a v  a  2s  .com*/
    public static void removeHeaderView(RecyclerView recyclerView) {

        RecyclerView.Adapter outerAdapter = recyclerView.getAdapter();

        if (outerAdapter != null
                && outerAdapter instanceof MTFRecyclerViewAdapterWrapper) {

            int headerViewCounter = ((MTFRecyclerViewAdapterWrapper) outerAdapter)
                    .getHeaderViewsCount();
            if (headerViewCounter > 0) {
                View headerView = ((MTFRecyclerViewAdapterWrapper) outerAdapter)
                        .getHeaderView();
                ((MTFRecyclerViewAdapterWrapper) outerAdapter)
                        .removeFooterView(headerView);
            }
        }
    }
    
    public static void removeFooterView(RecyclerView recyclerView) {

        RecyclerView.Adapter outerAdapter = recyclerView.getAdapter();

        if (outerAdapter != null
                && outerAdapter instanceof MTFRecyclerViewAdapterWrapper) {

            int footerViewCounter = ((MTFRecyclerViewAdapterWrapper) outerAdapter)
                    .getFooterViewsCount();
            if (footerViewCounter > 0) {
                View footerView = ((MTFRecyclerViewAdapterWrapper) outerAdapter)
                        .getFooterView();
                ((MTFRecyclerViewAdapterWrapper) outerAdapter)
                        .removeFooterView(footerView);
            }
        }
    }
}

Related Tutorials