问题描述
我试图写一个$ C $下一个回收视图无尽的滚动。这是片段,给了我一个编译器错误:
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);
和mLayoutManager是类RecyclerView.LayoutManager
And mLayoutManager is an object of class RecyclerView.LayoutManager
推荐答案
mLayoutManager是类RecyclerView.LayoutManager的对象
是不对的,你应该使用 android.support.v7.widget.LinearLayoutManager
为 mLayoutManager
,这样:
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);
然后 mLayoutManager.findFirstVisibleItemPosition();
调用应该是确定的 onScrolled(...);
then mLayoutManager.findFirstVisibleItemPosition();
call should be ok in onScrolled(...);
.
希望这有助于!
这篇关于安卓:无法解析法“findFirstVisibleItemPosition()”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!