get first visible position of recycler view - Android User Interface

Android examples for User Interface:RecyclerView

Description

get first visible position of recycler view

Demo Code


import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

public class Main{
    /**//w ww  .j  ava 2s.  com
     * get first visible position of recycler view
     *
     * @param rv
     * @return
     */
    public static int getFirstVisiblePosition(RecyclerView rv) {
        if (rv != null) {
            final RecyclerView.LayoutManager layoutManager = rv
                    .getLayoutManager();
            if (layoutManager instanceof LinearLayoutManager) {
                return ((LinearLayoutManager) layoutManager)
                        .findFirstVisibleItemPosition();
            }
        }
        return 0;
    }
}

Related Tutorials