After spending more time on it than I'd like, I have solved this issue, and 
wanted to post the outcome back here.

Turns out it's not an SDK problem, but it is an issue with the documentation 
I linked to earlier, 
http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog. The 
last Java code block on that page contains this line:

View layout = inflater.inflate(R.layout.custom_dialog,
                               (ViewGroup) findViewById(R.id.layout_root));

Now, I thought this looked a bit odd, because the call to findViewById() is 
occurring in the context of the Activity where this code resides, *not* the 
Dialog that's being created - but R.id.layout_root is in the layout of the 
custom dialog, And sure enough, if you debug through this example and 
examine the value of findViewById(R.id.layout_root), it's null. But the code 
works anyway.

My problem stemmed from having added an ID of layout_root to an element in 
the layout *of the calling Activity*. So, findViewById(R.id.layout_root) is 
now finding that View instead, is passing it to the inflate() call, and 
things rapidly go downhill. It's essentially a scope problem, not surprising 
for a case of "but I haven't changed that code!" [And somewhere, we probably 
ought to have a discussion about the scope of resource IDs, but that's 
outside the, um, scope of this post.]

The fix is easy: either rename one of the layout_root elements, or easier 
still... Since the original findViewById() call was returning null anyway, 
it turns out we don't even need it, and it's safer to change the inflate() call 
as follows:

View layout = inflater.inflate(R.layout.custom_dialog, *null*);

Toward this end, I'd like to see the relevant example in the documentation 
changed. Can anyone remind me of where to suggest doc updates?

String

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to