Challenge for Chapter 16 - Which View


#1

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?

Thanks
Dave

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


<TextView
android:layout_width="wrap_content"
android:layout_height=“wrap_content”

    android:paddingLeft="4dp"
    android:paddingRight="4dp"
    android:text="There are no Crimes"/>

#2

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


#3

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:

startActivityForResult(…).

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.

Thanks,
Dave