get last visible position of recycler view - Android User Interface

Android examples for User Interface:RecyclerView

Description

get last visible position of recycler view

Demo Code


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

public class Main{
    /**/*from  w w w.  ja  va2s.c o  m*/
     * get last visible position of recycler view
     *
     * @param rv
     * @return
     */
    public static int getLastVisiblePosition(RecyclerView rv) {
        if (rv != null) {
            final RecyclerView.LayoutManager layoutManager = rv
                    .getLayoutManager();
            if (layoutManager instanceof LinearLayoutManager) {
                return ((LinearLayoutManager) layoutManager)
                        .findLastVisibleItemPosition();
            }
        }
        return 0;
    }
}

Related Tutorials