简体   繁体   English

如何使用 ROOM 库将数千条记录从本地数据库加载到 recyclerview 而不阻塞 UI

[英]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.

相关问题 如何使用Room Persistence Library从本地数据库更新文档? - how to update a document from local database using Room Persistence Library? 如何在不阻塞 UI 线程的情况下用 Room 中的数据填充微调器 - How to fill spinner with data from Room without blocking UI thread 如何在 Activity 中填充没有 RecyclerView 的 Room 数据库 - How to populate Room database without RecyclerView in Activity 当我使用 Coroutines 向数据库添加新项目时,Room 数据库如何在 UI 中更新我的 RecyclerView? - How can Room database update my RecyclerView in the UI when I have added a new item to the database using Coroutines? RecyclerView:重新加载数据而不阻塞UI线程 - RecyclerView: Reloading the data without blocking the UI thread 如何在不使用recyclerview中的库的情况下从服务器分页数据? - How to paginate data from server without using library in recyclerview? 如何从RecyclerView项目中保存Room数据库中的两组数据 - How to save two sets of data in Room database from RecyclerView items 如何在recyclerview的顶部显示房间数据库中的最后一项 - How to show the last item from room database at top in recyclerview 如何从房间数据库和 RecyclerView 中删除项目并更新列表 - How to delete an item from Room Database and RecyclerView and updating the list 在使用Room从ChildActivity中单击按钮后,如何从数据库中的MainActivity中加载的RecyclerView中删除对象列表 - How do I delete a list of objects from RecyclerView loaded in MainActivity from database upon button click from ChildActivity using Room
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM