I tried to do the challenge in CrimeDetailFragment, it works fine but when there is only one crime available in recyclerView, i need to delete it twice, addmenu() is used in onViewCreated
I’m not sure I can help you much without seeing the bigger picture. Is there any way that you could share what you have via Github or something similar?
thank you for answering, I kind of solve the problem by adding a line of code to change recyclerView’s visibility to GONE when there are no crimes , but i still wonder what is the reason for this problem
I tried running your code and it seems all good on my end. I’m not exactly sure what is causing the issues, because it looks like you took the right approach to solve the challenge.
When we create a new crime, the title starts off as empty. Maybe that is what you were seeing.
Yeah, I understand not feeling great when you don’t know what is going wrong. Changing the visibility on the RecyclerView doesn’t solve the problem, it just hides it.
If you still cannot find what is causing issues, I recommend adding some logging inside the crimeLitViewModel.crimes.collect { ... } lambda expression. That should get invoked every time the data in the database changes, so if you are not seeing logs often, then you know that might be a place to dig into.