Challenge for Chapter 16 - Which View


I’m having trouble getting the Challenge done for Chapter 16. Which View are we supposed to use for the empty view? I’m using XML like that posted below, and am getting run time errors. I’ve tried ViewGroup, View and even ListView. The text just says to use “another View of some kind as the empty view.” Can someone specify which kind to use?


?xml version=“1.0” encoding=“utf-8”?>


    android:text="There are no Crimes"/>


What runtime errors are you getting? For the code you posted, you will at the very least want to use FrameLayout instead of ViewGroup.


Thanks Bill Phillips. That did the trick. Actually I used a LinearLayout. I had a bad grasp on what was a “View” and which classes inherit from View. While doing the challenge, I believe I found what might be some unnecessary code. In your onOptionsItemSelected(MenuItem item) you have:


As far as I can see, you make no use of any result, and you could have used startActivity(…) instead. It does no harm to use startActivityForResult, but it is confusing. If there is some reason for using it, please let me know. It is not mentioned in the text. I noticed it, because one can copy the menu item code into the button handler that is asked for in the challenge.

I am enjoying your book a lot.