android – RecyclerView滚动侦听器的方法onscolled自动调用而不滚动

在实施分页时.我遇到了这个问题.不滚动onscrolled方法不断调用.
请检查下面的代码.

作为参考,我使用的是Endless Scrolling with AdapterViews and RecyclerView

还有一个演示示例this.

我正在从API请求数据.所以我实施了凌空.安装完成后,发生了奇怪的事情OnScrolled方法连续调用而不滚动.
以下是我的代码.

    HomeFragment.java

    view = inflater.inflate(R.layout.fragment_home,container,false);

    tvNoDataFound = (TextView) view.findViewById(R.id.tv_no_data_found);
    recyclerView = (RecyclerView)view.findViewById(R.id.listView);

    linearlayoutmanager = new linearlayoutmanager(getActivity());

    recyclerView.setnestedScrollingEnabled(false);

    recyclerView.setLayoutManager(linearlayoutmanager);


    context = view.getContext();

    // Lookup the swipe container view
    swipeProjects = (SwipeRefreshLayout)view.findViewById(R.id.swipeProjects);

    // Setup refresh listener which triggers new data loading
    swipeProjects.setonRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            // Your code to refresh the list here.
            // Make sure you call swipeContainer.setRefreshing(false)
            // once the network request has completed successfully.
            getProjects(0,0);
        }
    });
    // Configure the refreshing colors
    swipeProjects.setColorSchemeResources(android.R.color.holo_blue_bright,android.R.color.holo_green_light,android.R.color.holo_orange_light,android.R.color.holo_red_light);

    Listlinearlayoutmanager) {

        @Override
        public void onLoadMore(int page,int totalItemsCount) {

            Log.e("here scrolling","scrolling---"+page+"---"+totalItemsCount);

            // Triggered only when new data needs to be appended to the list
            // Add whatever code is needed to append new items to the bottom of the list
            List

从服务器获得响应后,我使用下面的函数来设置适配器.

public Listlistadapter(list,getActivity(),HomeFragment.this);
        recyclerView.setAdapter(adapter);
    }
    return list;
}

在上面的代码中,我的第一个API调用偏移0.我不知道是什么问题.是因为凌空异步请求吗?

最佳答案
是的,它会被调用.用这个克服一种方法

private boolean isLastItemdisplaying(RecyclerView recyclerView) {
    if (recyclerView.getAdapter().getItemCount() != 0) {
        int lastVisibleItemPosition = ((linearlayoutmanager) recyclerView.getLayoutManager()).findLastCompletelyVisibleItemPosition();
        if (lastVisibleItemPosition != RecyclerView.NO_POSITION && lastVisibleItemPosition == recyclerView.getAdapter().getItemCount() - 1)
            return true;
    }
    return false;
}

现在用onScolled方法检查该方法.

 boolean a = isLastItemdisplaying(recycler_product);
 if(a)
     {
        List

相关文章

这篇“android轻量级无侵入式管理数据库自动升级组件怎么实现...
今天小编给大家分享一下Android实现自定义圆形进度条的常用方...
这篇文章主要讲解了“Android如何解决字符对齐问题”,文中的...
这篇文章主要介绍“Android岛屿数量算法怎么使用”的相关知识...
本篇内容主要讲解“Android如何开发MQTT协议的模型及通信”,...
本文小编为大家详细介绍“Android数据压缩的方法是什么”,内...