[英]How to load thousands of records from local database to recyclerview without blocking UI using ROOM library
I am using local database to load records on recyclerview the problem is the size of records its about six thousand and when I click to open or show those records in recyclerview my device stuck for a few seconds a blank screen appear and when few seconds pass it appear and show records.我正在使用本地数据库在 recyclerview 上加载记录,问题是记录的大小约为六千,当我单击打开或在 recyclerview 中显示这些记录时,我的设备卡住了几秒钟,出现空白屏幕,几秒钟过去了出现并显示记录。 Is there a way to load thousands of records or data on recyclerview without blockage of UI?
有没有办法在不阻塞 UI 的情况下在 recyclerview 上加载数千条记录或数据? please let me know thanks
请让我知道,谢谢
copy & paste this method to your Activity / Baseactivity.将此方法复制并粘贴到您的活动/基础活动中。 and call this after
yourRecyclerview.setAdapter(YourAdapter)
并在
yourRecyclerview.setAdapter(YourAdapter)
之后调用它
public void PagginationRecyclerView(RecyclerView rv) {
rv.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
int total = layoutManager.getItemCount();
int currentLastItem = layoutManager.findLastVisibleItemPosition();
if (currentLastItem == total - 1) {
Toast.makeText(BaseActivity.this, "Load Next", Toast.LENGTH_SHORT).show();
// Request to Database to load more data
}
}
});
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.