我正在使用从Parse.com
数据库加载数据的endless Recyclerview
。我面临的问题是它显示了两个加载图像,如下面的屏幕所示。我想在时间显示一个项目然后在滚动时显示图标,然后加载下一个项目。
EndlessScroll的代码是 -
public abstract class EndlessScroll extends RecyclerView.OnScrollListener {
public static String TAG = EndlessScroll.class.getSimpleName();
private int previousTotal = 0; // The total number of items in the dataset after the last load
private boolean loading = true; // True if we are still waiting for the last set of data to load.
private int visibleThreshold = 2; // The minimum amount of items to have below your current scroll position before loading more.
int firstVisibleItem, visibleItemCount, totalItemCount;
Context context;
private int current_page = 1;
private LinearLayoutManager mLinearLayoutManager;
public EndlessScroll(LinearLayoutManager linearLayoutManager, Context context) {
this.mLinearLayoutManager = linearLayoutManager;
this.context = context;
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
visibleItemCount = recyclerView.getChildCount();
totalItemCount = mLinearLayoutManager.getItemCount();
firstVisibleItem = mLinearLayoutManager.findFirstVisibleItemPosition();
if (loading) {
if (totalItemCount > previousTotal) {
loading = false;
previousTotal = totalItemCount;
}
}
if (!loading && (totalItemCount - visibleItemCount)
<= (firstVisibleItem + visibleThreshold)) {
// End has been reached
// Do something
current_page++;
onLoadMore(current_page);
loading = true;
}
}
public abstract void onLoadMore(int current_page);
}
我已经开始在Android工作了。
我不确定为什么加载行为有问题。
非常感谢您的帮助/建议/任何指针。