![](/img/trans.png)
[英]How to make SwipeRefreshLayout work when the RecyclerView is empty
[英]How to make Paging library work with reverse recyclerview?
如何使用最新的分页与无休止的反向回收视图进行聊天?
我有线性布局,反向布局为真:
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
layoutManager.setReverseLayout(true);
layoutManager.setStackFromEnd(true);
和内部滚动侦听器:
@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();
}
}
}
获取消息的查询:
SELECT * FROM Message WHERE chatId = :chatId ORDER BY dbId ASC
用于下面的房间;
@Query("SELECT * FROM Message WHERE chatId = :chatId ORDER BY dbId ASC")
DataSource.Factory<Integer,Message> fetchAll(String chatId);
问题是如果我在查询中使用ASC,列表会自动滚动并获取其他消息。 如果使用DESC,则消息列表不按顺序排列。
有人可以帮忙吗?
我觉得这很有意思
layoutManager.setStackFromEnd(假);
layoutManager.setReverseLayout(真);
如果您在房间数据库中有一个增量列表(行索引/控制),您可以在DESC模式下对其进行排序
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.