views:

210

answers:

1

Is there any way to query a root view of an activity for all of its child views even before the root view or its children have been inflated? I guess what I'm looking for is whether a view knows ahead of time what children it will have before it gets inflated, and can I get that list in some way. Bizarre I realize, but I think it will help me with some unconventional automation testing I'm working on. I haven't found anything in the API like this, so I'm hoping the community knows something spiff that will help.

Thanks!

+1  A: 

I doubt it.

An Activity doesn't have any knowledge of its view (it just has its root window) until you call setContentView() in the onCreate() method.

There is a construct called ViewStub which allows you to delay inflating certain parts of the UI until you need them, but even then you wouldn't actually know anything about the child views until you inflate it.

Something else that may be of interest is the ViewTreeObserver and its subclasses. That allows you to receive notifications when a view hieararchy is changing.

Your test automation certainly does sound unconventional. Intriguing :)

Christopher
Thanks Christopher, it's the same story as before: I need to know when everything in the root view has been loaded so our tests (that don't extend from InstrumentationTestCase) don't stumble on lists or tables that are still loading and so aren't accessible when the test begins running. I'm thinking of just adding a collection of some sort to each activity that I can call and iterate over using findViewById as a way to say, ok, this activity is now ready to mess with...
Derrick
Hmm.. someone asked a similar question recently where they weren't extending InstrumentationTestCase. But as far as I'm aware, I believe views should all be inflated and accessible as soon as setContentView returns?
Christopher