[英]Detect if the recyclerview is updated
I have a RecyclerView
that contains a list of messages.我有一个包含消息列表的RecyclerView
。 I want to make a notification every time the user receive a message.我想在用户每次收到消息时发出通知。 Because an update on the RecyclerView
means that there is a new message.因为RecyclerView
的更新意味着有新消息。 I tried to make notifications when listening to the Firebase database messages node but it gives me a lot of notifications and make the app looks messy.我试图在收听 Firebase 数据库消息节点时发出通知,但它给了我很多通知并使应用程序看起来很混乱。 Any suggestion?有什么建议吗?
You can use the RecyclerView.AdapterDataObserver to observe your adapter's data.您可以使用RecyclerView.AdapterDataObserver来观察适配器的数据。
it gives you a lot of options to to observe your adapter's data它为您提供了许多观察适配器数据的选项
kotlin example:科特林示例:
mAdapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver(){
override fun onChanged() {
// do work here
super.onChanged()
}
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.