如何使用反向回收视图使Paging库工作?

kru*_*ile 9 java android chat android-recyclerview

如何使用最新的分页与无休止的反向回收视图进行聊天?

我有线性布局,反向布局为真:

LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setReverseLayout(true);
layoutManager.setStackFromEnd(true);
Run Code Online (Sandbox Code Playgroud)

和内部滚动侦听器:

@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);
    int visibleItemCount = layoutManager.getChildCount();
    int totalItemCount = layoutManager.getItemCount();
    int firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition();

    if (!isLoading && !isLastPage) {
        if ((visibleItemCount + firstVisibleItemPosition) >= totalItemCount
                && firstVisibleItemPosition >= 0
                && totalItemCount >= PAGE_SIZE) {
            loadMoreItems();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

获取消息的查询:

SELECT * FROM Message WHERE chatId = :chatId ORDER BY dbId ASC
Run Code Online (Sandbox Code Playgroud)

用于下面的房间;

@Query("SELECT * FROM Message WHERE chatId = :chatId ORDER BY dbId ASC")
DataSource.Factory<Integer,Message> fetchAll(String chatId);
Run Code Online (Sandbox Code Playgroud)

问题是如果我在查询中使用ASC,列表会自动滚动并获取其他消息.如果使用DESC,则消息列表不按顺序排列.

有人可以帮忙吗?

Vic*_*scu 3

我认为这就足够了

layoutManager.setStackFromEnd(false);


布局管理器.setReverseLayout(true);

如果房间数据库中有增量列表(行索引/控制器),您可以在 DESC 模式下对其进行排序