Search code examples
androidkotlinandroid-databindingandroid-livedata

welcome screen glimpse while data is loading from database


My app loads a list of training entities from the database into a RecyclerView. There's a welcomeTextView with visibility="@{viewModel.listHasNoData}". It replaces the RecyclerView if the database is empty yet or if the user has deleted all data. The problem is that I have a split-second glimpse of this welcomeTextView every time I open the app while the data is being loaded. I've found a walkaround by saving a boolean isDatabaseEmpty to SharedPreferences when closing the app. But I believe there should be a more graceful solution.


Solution

  • Set visibility of welcomeTextView to gone by default. After the query into database , if there is no data then continue with the same logic . visibility="@{viewModel.listHasNoData}"