Displaying empty layout when no adapter objects exist


Hi All,

I’ve been browsing online and it looks like showing a default view when no objects exist is common practice: i.e. "No crimes yet!"
I’ve looked at a few suggestions online but I’m not sure how to implement this on the convertView. If the convertView is the existing list item that gets reused when regenerating the list, would it be acceptable to specify an alternate layout inside of the if logic:

if (convertView == null){
     //rather than inflate, get the adapter count (or the crime object count) and if equals 0, display the empty .xml layout
 inflate list

Does that make sense?


Not sure how far you’ve gotten in the book, but this scenario is discussed in Chp. 16 - on pg 270. ListView actually has an automatic switching feature that allows toggling layouts between a ListView with an empty/non-empty adapter. The layout is inflated in onCreateView of the Fragment class. ConvertView is the individual list item view that gets passed into the getView method for the nested ArrayAdapter class of the Fragment. In order to conserve memory, the paltform attempts to reuse/recycle views that have been scrolled out of view in the window. If ConvertView is null, then getView inflates a fresh view from the list item layout.