Thanks, I'll update the documentation.

On Sat, Feb 19, 2011 at 12:46 PM, davemac <[email protected]> wrote:

> I was just going by what the documentation says. This is from
> onInflate():
>
> >>> Start Android documentation...
> Called when a fragment is being created as part of a view layout
> inflation, typically from setting the content view of an activity.
> This will be called immediately after the fragment is created from a
> tag in a layout file. Note this is before the fragment's
> onAttach(Activity) has been called; all you should do here is parse
> the attributes and save them away. A convenient thing to do is simply
> copy them into a Bundle that is given to setArguments(Bundle).
>
> This is called every time the fragment is inflated, even if it is
> being inflated into a new instance with saved state. Because a
> fragment's arguments are retained across instances, it may make no
> sense to re-parse the attributes into new arguments. You may want to
> first check getArguments() and only parse the attributes if it returns
> null, the assumption being that if it is non-null those are the same
> arguments from the first time the fragment was inflated. (That said,
> you may want to have layouts change for different configurations such
> as landscape and portrait, which can have different attributes. If so,
> you will need to re-parse the attributes each time this is called to
> generate new arguments.)
> >>> Stop Android documentation...
>
> The AttributeSet passed to onInflate() will contain the attributes
> from the <fragment> tag in the newest layout file, i.e., the one for
> the configuration I'm now in. These attributes could have changed with
> an orientation change, and are meaningful to my fragment that I'm
> building, but they will not be available to my fragment at all until
> it's too late. As it stands now, I have no way to re-parse the
> attributes to generate new arguments.
>
> - dave
>
> On Feb 19, 3:16 pm, Dianne Hackborn <[email protected]> wrote:
> > Oh and it really doesn't make sense to set the arguments from the inflate
> > attributes.  I mean, the arguments are the ones coming from the content
> view
> > hierarchy.  You don't need to save them away, that just duplicates them
> > elsewhere, and potentially leads to ambiguous situation such as if you
> have
> > different arguments for different layouts, in which case should the last
> > restored arguments be used or the ones from the new layout?
> >
> > On Sat, Feb 19, 2011 at 12:14 PM, Dianne Hackborn <[email protected]
> >wrote:
> >
> >
> >
> > > Well basically onInflate() is called when it needs to be, which is when
> the
> > > content view of the activity is being inflated.  If that isn't working
> for
> > > you...  you will need to do something else.  There is no other point at
> > > which this can be called, the on and only point it can happen is during
> > > inflation of the activity's view hierarchy.
> >
> > > On Sat, Feb 19, 2011 at 11:53 AM, davemac <[email protected]>
> wrote:
> >
> > >> I created a bug report for this a couple of days ago, but it doesn't
> > >> seem to have received any attention:
> >
> > >>http://code.google.com/p/android/issues/detail?id=14796
> >
> > >> To reproduce the problem, add the following callback override to the
> > >> TitlesFragment class in FragmentLayout.java under the ApiDemos project
> > >> in samples for Honeycomb Preview:
> >
> > >>        @Override
> > >>        public void onInflate(AttributeSet attrs, Bundle
> > >> savedInstanceState) {
> > >>                Bundle args = new Bundle();
> > >>                for(int i=0; i<attrs.getAttributeCount(); i++) {
> > >>                Log.v("14796", "    " + attrs.getAttributeName(i) +
> > >>                                " = " + attrs.getAttributeValue(i));
> > >>                args.putString(attrs.getAttributeName(i),
> > >>                               attrs.getAttributeValue(i));
> > >>                }
> > >>                this.setArguments(args);
> > >>                super.onInflate(attrs, savedInstanceState);
> > >>        }
> >
> > >> This is doing what the the documentation says you should do. That is,
> > >> take attributes passed in and save them in the arguments bundle on the
> > >> fragment instance. However, if you launch this activity then rotate
> > >> the screen, the activity crashes with an IllegalStateException. And it
> > >> does that because onInflate() gets called way too late when Android is
> > >> rebuilding the activity and its fragments. If the layout for the other
> > >> orientation is different that the previous layout, you'll have no way
> > >> to use any of the attributes in onCreateView() for the fragment,
> > >> because onInflate() isn't being called until later.
> >
> > >> I haven't come up with a workaround either. The fragment can't even
> > >> see the activity until onAttach(), and you can't set the arguments
> > >> bundle once onAttach() has been called.
> >
> > >> The sample activities so far haven't tried to utilize this feature, so
> > >> perhaps it won't affect most people. But for those who need or want
> > >> it, it doesn't seem to work.
> >
> > >> --
> > >> 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
> >
> > > --
> > > Dianne Hackborn
> > > Android framework engineer
> > > [email protected]
> >
> > > Note: please don't send private questions to me, as I don't have time
> to
> > > provide private support, and so won't reply to such e-mails.  All such
> > > questions should be posted on public forums, where I and others can see
> and
> > > answer them.
> >
> > --
> > Dianne Hackborn
> > Android framework engineer
> > [email protected]
> >
> > Note: please don't send private questions to me, as I don't have time to
> > provide private support, and so won't reply to such e-mails.  All such
> > questions should be posted on public forums, where I and others can see
> and
> > answer them.
>
> --
> 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
>



-- 
Dianne Hackborn
Android framework engineer
[email protected]

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

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