Re: [android-developers] Fragment init confusion

2011-04-10 Thread Dianne Hackborn
On Sun, Apr 10, 2011 at 1:07 AM, Brill Pappin  wrote:

> But onCreate is called before onCreateView... which is where my confusion
> really stems from.
> The fact that I need to initialize my internal components in onCreateView
> means it has to happen after onCreate.
>

Well any initialization that involves your views needs to be done in
onCreateView() or later.  Just don't put that code in onCreate().


> Also, I'm not clear on whether i can access my internal components after
> calling inflater.inflate in onCreateView or not. Since I have to return the
> View created there, the parent activity doesn't have it yet, so i'm
> expecting a call to getActivity().findViewById to fail... unless just the
> act of inflating will make them available (black box magic code)?
>

Your fragment should never use getActivity().findViewById() to access its
internal components.  Jat call View.findViewById() on your own view
hierarchy.

-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Fragment init confusion

2011-04-10 Thread Brill Pappin
But onCreate is called before onCreateView... which is where my confusion 
really stems from.
The fact that I need to initialize my internal components in onCreateView 
means it has to happen after onCreate.

Also, I'm not clear on whether i can access my internal components after 
calling inflater.inflate in onCreateView or not. Since I have to return the 
View created there, the parent activity doesn't have it yet, so i'm 
expecting a call to getActivity().findViewById to fail... unless just the 
act of inflating will make them available (black box magic code)?

I'm sure a lot of this could be cleared up by executing code, but I'm in a 
bit of a complex quagmire of not-yet-converted code, trying to sort out what 
needs refactoring and what pieces go where in the Fragment world :)

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

Re: [android-developers] Fragment init confusion

2011-04-10 Thread Dianne Hackborn
Any initialization that involves views associated with the fragment must be
done in onCreateView() (or I guess later), since that is the place where you
actually create and return your view hierarchy.

There is basically no reason to use onRestoreInstanceState(), and no need
for this with fragment.  For both activities and fragments, just restore the
data from the "savedState" variable that is passed to onCreate() etc.

On Sat, Apr 9, 2011 at 11:59 PM, Brill Pappin  wrote:

> I'm attempting to convert an app from a standard activity based app to a
> fragment based app and I'm a bit confused on where I should place code that
> i used to have in onCreate(Bundle).
>
> The lifecycle is pretty clear that the sequence is onCreate() ->
> onCreateView(). Additionally, it looks like onCreateView takes the place of
> onRestoreInstanceState in Activity.
>
> Whats confusing me is i used to set the layout in the activity onCreate and
> then initialize most of my internal connections to view components (fairly
> standard stuff). However now since I have not set lay layout and I do
> explicitly load the fragment layout in onCreateView, where does all that
> init code that I used to put in onCreate go (leave it in onCreate() or move
> it to onCreateView)?
> If i use onCreateView as a replacement for onRestoreInstanceState can I
> expect that my components initialized in onCreate to be available for the
> manual (read dynamic) restore?
>
> If my components are already available because they were part of the
> activity's layout, why then am i loading the fragment's layout in the
> onCreateView() ?
>
>
>
>  --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en




-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Fragment init confusion

2011-04-10 Thread Brill Pappin
I'm attempting to convert an app from a standard activity based app to a 
fragment based app and I'm a bit confused on where I should place code that 
i used to have in onCreate(Bundle).

The lifecycle is pretty clear that the sequence is onCreate() -> 
onCreateView(). Additionally, it looks like onCreateView takes the place of 
onRestoreInstanceState in Activity.

Whats confusing me is i used to set the layout in the activity onCreate and 
then initialize most of my internal connections to view components (fairly 
standard stuff). However now since I have not set lay layout and I do 
explicitly load the fragment layout in onCreateView, where does all that 
init code that I used to put in onCreate go (leave it in onCreate() or move 
it to onCreateView)?
If i use onCreateView as a replacement for onRestoreInstanceState can I 
expect that my components initialized in onCreate to be available for the 
manual (read dynamic) restore?

If my components are already available because they were part of the 
activity's layout, why then am i loading the fragment's layout in the 
onCreateView() ?



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