Skip to content
Advertisement

Android RecyclerView content not updating after notifyItemInserted

I’ve got a RecyclerView that needs to update in real-time when content is received. It successfully shows all the content at first load. When attempting to add a new item dynamically, it makes no difference. Is there anything I’m doing wrong here? Much appreciated!

MainActivity:

JavaScript

Adapter:

Standard adapter code. Simply shows all the items in the recyclerview.

JavaScript

Advertisement

Answer

Since you mentioned ‘realtime’, I’m guessing this could be a thread issue. Your code seems correct. It could be that the adapter needs to be refreshed in a runOnUiThread function. Try this:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement