Challenge: An Empty View for the List

Currently, when CriminalIntent launches, it displays an empty list – a big black void. You should give users something to interact with when there are no items in the list.

ListView, because it is a subclass of AdapterView, supports a special View called the “empty view” for this very scenario. If you specify a view for the empty view, the ListView will automatically switch between showing it when there are no items, and showing the list when there are some items.

You can specify the empty view in code using the following AdapterView method:

 ​ ​ ​ ​p​u​b​l​i​c​ ​v​o​i​d​ ​s​e​t​E​m​p​t​y​V​i​e​w​(​V​i​e​w​ ​e​m​p​t​y​V​i​e​w​)​

Or you can create a layout in XML that specifies both the ListView and the empty ...

Get Android Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.