I'm trying to write a code for endless scroll on 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've written before is:
mLayoutManager = new LinearLayoutManager(this);
And mLayoutManager is an object of class RecyclerView.LayoutManager
mLayoutManager is an object of class RecyclerView.LayoutManager
is wrong, you should use android.support.v7.widget.LinearLayoutManager
for mLayoutManager
, so:
mLayoutManager = new LinearLayoutManager(this);
//above 'LinearLayoutManager' is from
//'android.support.v7.widget.LinearLayoutManager'
mRecyclerView.setLayoutManager(mLayoutManager);
then mLayoutManager.findFirstVisibleItemPosition();
call should be ok in onScrolled(...);
.
Hope this help!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With