Android: Can't resolve findFirstVisibleItemPosition () method?

I am trying to write code for endless scrolling in a recycler view. This is the snippet that gives me a compiler error:

@Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { visibleItemCount = mLayoutManager.getChildCount(); totalItemCount = mLayoutManager.getItemCount(); pastVisiblesItems = mLayoutManager.findFirstVisibleItemPosition(); if ( (visibleItemCount+pastVisiblesItems) >= totalItemCount) { Log.v("...", "Last Item Wow !"); } 

And the declaration I wrote earlier:

 mLayoutManager = new LinearLayoutManager(this); 

And mLayoutManager is an object of the RecyclerView.LayoutManager class

+5
android android-recyclerview
Mar 29 '15 at 8:14
source share
1 answer

mLayoutManager is an object of class RecyclerView.LayoutManager is incorrect, you must use android.support.v7.widget.LinearLayoutManager for mLayoutManager , therefore:

 mLayoutManager = new LinearLayoutManager(this); //above 'LinearLayoutManager' is from //'android.support.v7.widget.LinearLayoutManager' mRecyclerView.setLayoutManager(mLayoutManager); 

then mLayoutManager.findFirstVisibleItemPosition(); the call should be in order onScrolled(...); .

Hope this help!

+17
Mar 29 '15 at 15:46
source share



All Articles