Step #2: Showing an Empty View
Dumping the user onto an empty screen at the outset is rather unfriendly. A typical solution is to have an “empty view” that is displayed when there is nothing else to show. That “empty view” usually has a message that tells the user what to do first.
We created the empty view back in an earlier tutorial, but we set its visibility to GONE. Let’s revert that change, so the empty view appears to the user.
In onViewCreated() of RosterListFragment, remove the binding.empty.visibility = View.GONE line, leaving you with:
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val adapter = RosterAdapter(
layoutInflater,
onCheckboxToggle = { motor.save(it.copy(isCompleted = !it.isCompleted)) },
onRowClick = ::display)
binding.items.apply {
setAdapter(adapter)
layoutManager = LinearLayoutManager(context)
addItemDecoration(
DividerItemDecoration(
activity,
DividerItemDecoration.VERTICAL
)
)
}
adapter.submitList(motor.items)
}
Now when you run the app, you will see… some placeholder text:
We will replace that text with a better message shortly.
Prev Table of Contents Next
This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.