[英]load more data on scroll to top in recyclerview
I trying to load more data on scroll to top recyclerview Like Whatsapp chat .我试图在滚动到顶部 recyclerview 时加载更多数据,例如 Whatsapp chat 。
my adapter is contain multiple views我的适配器包含多个视图
I loading few rows from sqlite to display in recyclerview and load more data when scroll the top.我从 sqlite 加载几行以显示在 recyclerview 中,并在滚动顶部时加载更多数据。 when i load the more data the app is crashed当我加载更多数据时,应用程序崩溃
02-20 22:57:01.324 6833-6833/ E/AndroidRuntime: FATAL EXCEPTION: main
Process: , PID: 6833
java.lang.NullPointerException
at .adapters.PrivateChatAdapter$ViewHodler.setSenderMsg(PrivateChatAdapter.java:208)
at .adapters.PrivateChatAdapter.onBindViewHolder(PrivateChatAdapter.java:124)
at .adapters.PrivateChatAdapter.onBindViewHolder(PrivateChatAdapter.java:46)
the linearlayoutmanger is linearLayoutManager.setStackFromEnd(true);
线性布局管理器是linearLayoutManager.setStackFromEnd(true);
0 <---- i want to load the new data here
1
2
3
4
5
6
When i add the new data to arraylist当我将新数据添加到 arraylist 时
arrayMsgs.add(0, new PrivateMsg.Builder(PrivateMsg.LOADING_MORE_MSG, 0, true).build());
privateChatAdapter.notifyItemInserted(0);
The old item in position 0 is repeated位置 0 的旧项重复
I've solved the issue by resetting the adapter as below :我通过如下重置适配器解决了这个问题:
recyclerview.setAdapter(privateChatAdapter);
after adding data to position zero in arraylist将数据添加到 arraylist 中的位置零后
Maybe because the views item stored in cache of the recyclerview可能是因为视图项存储在 recyclerview 的缓存中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.