That's because the view hierarchy hasn't been added to the window manager. You find out it has been added in View.onAttachedToWindow().
On Mon, Jan 17, 2011 at 8:41 AM, APF <[email protected]> wrote: > I find that View.getWindowToken() always returns null, even when > invoked from the main Activity during onCreate. For example: > > TextView tv = new TextView(this); > tv.setText("Hello, Android"); > setContentView(tv); > tv.getWindowToken(); // will equal null > > Manually adding it to the window manager (addView) doesn't help > either. > > When does a View have a window token? How do I get a valid window > token? > > TIA. > > -- > 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]<android-developers%[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

