set RecyclerView HeaderView - Android User Interface

Android examples for User Interface:RecyclerView

Description

set RecyclerView HeaderView

Demo Code


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

public class Main{
    /*  w w w  . j  av  a  2s  .  c om*/
    public static void setHeaderView(RecyclerView recyclerView, View view) {
        RecyclerView.Adapter outerAdapter = recyclerView.getAdapter();

        if (outerAdapter == null
                || !(outerAdapter instanceof MTFRecyclerViewAdapterWrapper)) {
            return;
        }

        MTFRecyclerViewAdapterWrapper headerAndFooterAdapter = (MTFRecyclerViewAdapterWrapper) outerAdapter;
        if (headerAndFooterAdapter.getHeaderViewsCount() == 0) {
            headerAndFooterAdapter.addHeaderView(view);
        }
    }
}

Related Tutorials