Emre A. Yavuz wrote:
> 
> Hi,
>  
> I was wondering whether anybody has tried calling setContentView() more
> than once in method onCreate() when creating an Activity. It seems only
> the last view is displayed. Or am I missing something here ?
>  
> Say we have an Activity:
>  
> * public* *class* SampleActivyt *extends* Activity {
>  
>     @Override 
> 
> *     public* *void* onCreate(Bundle savedInstanceState) {
> 
> *           super*.onCreate(savedInstanceState);
> 
>          setContentView(R.layout./layout1/);
>  
>          // DO SOMETHING HERE .... and when it is done change the view
>  
>          setContentView(R.layout./layout2/);
>  
>    }
> }

setContentView() does not have visual impact until *after* onCreate()
returns. If you call it twice, the net is that the user will only see
the second.

Moreover, if "DO SOMETHING HERE" is long enough to warrant a loading
screen, you *do not* want to be doing that work in onCreate(), anyway.
Use AsyncTask or something else to put it in a background thread.

> You can think of it as you have a "loading" screen while a
> computation is being done and once it's finished the view needs to be
> changed.

Use a FrameLayout to put your loading screen and the main view in one
layout. Set the main view to be android:visibility="gone" in the layout
file. Once your background thread is done doing its work, in the UI
thread (e.g., onPostExecute() in AsyncTask), make the loading screen be
View.GONE and your main view to be View.VISIBLE.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

Looking for Android opportunities? http://wiki.andmob.org/hado

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