我正在尝试在回收站视图上编写无限滚动的代码。这是给我编译错误的片段:
@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 !");
}
我之前写的声明是:
mLayoutManager = new LinearLayoutManager(this);
mLayoutManager是RecyclerView.LayoutManager类的对象
答案 0 :(得分:23)
mLayoutManager is an object of class RecyclerView.LayoutManager
错误,您应该android.support.v7.widget.LinearLayoutManager
使用mLayoutManager
,所以:
mLayoutManager = new LinearLayoutManager(this);
//above 'LinearLayoutManager' is from
//'android.support.v7.widget.LinearLayoutManager'
mRecyclerView.setLayoutManager(mLayoutManager);
然后mLayoutManager.findFirstVisibleItemPosition();
调用onScrolled(...);
。
希望这有帮助!