Lost in Challenge-land


#1

I’ve been stuck on the challenge and could use a help/hint/explanation on what I’m doing wrong.
From other’s posts, it seems that a call to inflate the layout replaces the superclass call in CrimeListFragment.java onCreateView()

where I’m trying out the automatic switching feature first via list_item_empty.xml:

[code]<?xml version="1.0" encoding="utf-8"?>

    <ListView 
        android:text="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    
    <TextView
        android:id="@android:id/empty"
        android:text="@string/crime_empty_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

[/code]

The app crashes with a RuntimeException message that "Your content must have a ListView whose id attribute is ‘android.R.id.list’"
So I gather from tommymato’s post that the ListView must be cast in code, and v refers to the inflated layout view.

Ok, save and re-run. The app doesn’t crash, but doesn’t load an empty view. Adding in view.setEmptyView(v.findViewById(android.R.id.empty)); the app again crashes upon startup with a NullPointerException runtime error.
I’m confused by this, since the empty view resource id doesn’t seem valid, even though I selected “@android:id/empty” from Eclipse’s suggestion pop-up.

Could someone please explain why the “automatic switching” feature doesn’t kick in, or why I get a NullPointerException when trying to set the empty view in code? Thanks!


#2

Problem solved.

After a day of parsing though articles on ListFragments and ListActivities, wondering if I had an issue with inflating the layout or setting the adapter, I noticed that my XML code sets “@android:id/list” as the text attribute, not the android id. Talk about a palm-to-the-face moment!

CrimeListFragment’s onCreateView() method inflated the layout without crashing. This was a lot more straightforward than I expected.


#3

I would never have found that in a million years, FYI. Good catch.