Reputation: 159
I have a RecyclerView
that contains a list of messages. 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.
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. Any suggestion?
Upvotes: 3
Views: 3054
Reputation: 4881
You can use the RecyclerView.AdapterDataObserver to observe your adapter's data.
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()
}
})
Upvotes: 10
Reputation: 138
After updating your adapter instance, call your_adapter.notifyDataSetChanged();
More details here.
Upvotes: 0