get RecyclerView Adapter Position - Android User Interface

Android examples for User Interface:RecyclerView

Description

get RecyclerView Adapter Position

Demo Code


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

public class Main{
    /*www .j a v a 2 s .  co  m*/
    public static int getAdapterPosition(RecyclerView recyclerView,
            RecyclerView.ViewHolder holder) {
        RecyclerView.Adapter outerAdapter = recyclerView.getAdapter();
        if (outerAdapter != null
                && outerAdapter instanceof MTFRecyclerViewAdapterWrapper) {

            int headerViewCounter = ((MTFRecyclerViewAdapterWrapper) outerAdapter)
                    .getHeaderViewsCount();
            if (headerViewCounter > 0) {
                return holder.getAdapterPosition() - headerViewCounter;
            }
        }

        return holder.getAdapterPosition();
    }
}

Related Tutorials