在实施分页时.我遇到了这个问题.不滚动onscrolled方法不断调用.
请检查下面的代码.
作为参考,我使用的是Endless Scrolling with AdapterViews and RecyclerView
还有一个演示示例this.
我正在从API请求数据.所以我实施了凌空.安装完成后,发生了奇怪的事情OnScrolled方法连续调用而不滚动.
以下是我的代码.
@H_404_14@ 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); List
从服务器获得响应后,我使用下面的函数来设置适配器.
@H_404_14@public List
最佳答案
是的,它会被调用.用这个克服一种方法
原文链接:https://www.f2er.com/android/430050.html@H_404_14@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; }
@H_404_14@ boolean a = isLastItemDisplaying(recycler_product); if(a) { List