我正在尝试为回收器 View 上的无尽滚动编写代码。这是给我一个编译器错误的代码段:

@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类的对象

最佳答案

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(...);调用应该可以。

希望对您有所帮助!

关于Android:无法解析 'findFirstVisibleItemPosition()'方法?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29327013/

10-09 01:12