Really? The Javadoc for View#inflate states:

Inflate a view from an XML resource. This convenience method wraps the
LayoutInflater class, which provides a full range of options for view
inflation.
Parameters
context         The Context object for your activity or application.
resource        The resource ID to inflate
root    A view group that will be the parent. Used to properly inflate
the layout_* parameters.


It doesn't mention that the resourceId needs to be a Layout or a
ViewGroup.
I don't really want to inflate the containing layout as its not
required and means I would need to remove the Views from it before
adding them to the dialog.
Can I define my 2 views directly in their own separate XML layout
files, ie with no containing (Linear)Layout and then inflate them?
Ie is the ResourceNotFoundException because I am supplying a
resourceId for a View instead of the resourceId/name of layout file?


On Nov 24, 12:02 am, viktor <[email protected]> wrote:
> You are on wrong way, you can inflate only layout (ViewGroup), but not
> child view,
> try to using View.inflate(activity, R.layout.how_to_play_dialog,
> null);
>
> On 23 Лис, 15:18, William Ferguson <[email protected]>
> wrote:
>
> > I am trying to create a dialog with a custom title and content views
> > but am running into ResourceNotFoundExceptions when I try and inflate
> > the views.
>
> >         final TextView titleView = (TextView) View.inflate(activity,
> > R.id.how_to_play_dialog_title, null);
>
> >         final WebView contentView = (WebView) View.inflate(activity,
> > R.id.how_to_play_dialog_text, null);
> >         contentView.loadData("<html><body>some text</body></html>",
> > "text/html", "utf-8");
>
> >         final AlertDialog.Builder builder = new
> > AlertDialog.Builder(activity);
> >         builder.setCustomTitle(titleView);
> >         builder.setView(contentView);
>
> > The above code throws the ResourceNotFound on each of the View
> > inflates even though I have res/layout/how_to_play_dialog.xml as the
> > follwing:
>
> > <?xml version="1.0" encoding="utf-8"?>
> > <LinearLayout xmlns:android="http://schemas.android.com/apk/res/
> > android"
> >     android:layout_width="wrap_content"
> >     android:layout_height="wrap_content"
> >     >
>
> >     <TextView android:id="@+id/how_to_play_dialog_title"
> >               android:layout_width="fill_parent"
> >               android:layout_height="wrap_content"
> >               android:text="@string/how_to_play_dialog_title"
> >               style="@style/dialogTitle"
> >     />
>
> >     <WebView android:id="@+id/how_to_play_dialog_text"
> >         android:layout_width="wrap_content"
> >         android:layout_height="wrap_content"
> >     />
> > </LinearLayout>
>
> > I can retrieve the Views (using findViewById) if I inflate the entire
> > layout first, but then I need to remove the views from the layout
> > before adding them to the Dialog.
>
> > Can't I just inflate the Views directly, using View#inflate?
>
> > The actual stacktrace is:
> > Caused by: android.content.res.Resources$NotFoundException: Resource
> > ID #0x7f0a000c type #0x12 is not valid
> >         at
> > android.content.res.Resources.loadXmlResourceParser(Resources.java:
> > 1874)
> >         at android.content.res.Resources.getLayout(Resources.java:731)
> >         at android.view.LayoutInflater.inflate(LayoutInflater.java:
> > 318)
> >         at android.view.LayoutInflater.inflate(LayoutInflater.java:
> > 276)
> >         at android.view.View.inflate(View.java:8665)
> >         at
> > au.com.xandar.jumblee.widget.DialogFactory.createHowToPlayDialog(DialogFact 
> > ory.java:
> > 35)
>
>

-- 
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