我想创建移动应用程序,它使用分页的RecyclerView,每次从dataBase 10条目加载,然后当列表到达底部时,我加载其他10个条目,所以我使用以下方法来通知我是否到达列表的末尾:
public boolean reachedEndOfList(int position) {
// can check if close or exactly at the end
return position == getItemCount() - 1;
}我使用这个函数来加载项目:
@Override
public void onBindViewHolder(Info holder, int position, List<Object> payloads) {
if (reachedEndOfList(position)) {
Log.d("reachedEnd", "true");
this.autoCompletesTmp = getTmp();
notifyDataSetChanged();
}
}getTmp()用另外10个项目更新了项目列表,但是当我到达列表底部时,我得到了这个异常:
java.lang.IllegalStateException: Cannot call this method while RecyclerView is computing a layout or scrolling发布于 2016-03-29 03:05:47
不久前我遇到了同样的问题:这很有帮助:
Handler handler = new Handler();
final Runnable r = new Runnable() {
public void run() {
//Do something like notifyDataSetChanged()
}
};
handler.post(r);https://stackoverflow.com/questions/36268462
复制相似问题