on orientation change, keep all objects, just change content view

by Wall-E » Wed, 30 Mar 2011 01:09:38 GMT


Sponsored Links
 I want to set the content view of my activity to a different resource
when user changes from portrait to landscape and vice versa.  I want
to try to avoid having the app call onCreate every time the user
changes orientation so I read that what I'm left with is using
onConfigurationChanged(...).  I can set the new content view but
unfortunately I have to re-initialize all my views.  Is there any way
to do this?

Also, currently I have the - android:configChanges="orientation" set
for my activity and am wondering what are the states and methods it
goes through when changing the orientation because I would like this
same behavior except I just want the content view to change.

If the only way/easiest way to accomplish this is for the app to re-
create the activity, how would I go about setting the content view
based on what the orientation is?  Would I do a check in the onCreate
method to see what the orientation is and then set the content view?

-- 



Re: on orientation change, keep all objects, just change content view

by TreKing » Wed, 30 Mar 2011 01:28:44 GMT


  http://developer.android.com/guide/topics/resources/index.html 
< http://developer.android.com/guide/topics/resources/index.html> ;
-------------------------------------------------------------------------------------------------
TreKing < http://sites.google.com/site/rezmobileapps/treking> ; - Chicago
transit tracking app for Android-powered devices

-- 


Sponsored Links


Re: on orientation change, keep all objects, just change content view

by Wall-E » Wed, 30 Mar 2011 02:11:54 GMT


 Ok so I read that site you linked to and although it gave me some
hints, it still didn't solve my problem.

So I already have my resource file in the layout-land folder.  I guess
the clarification I need is, how does the activity know to use that
resource file?  Do I name it the same thing and in my main layout
folder?  Also when creating my resource layout, I know I have the
option in the pull down to select portrait or landscape.  What I did
was create a layout resource with the same name as in the main layout
and made my changes and now when I go to the main layout and select
the orientation to be landscape it changes to the correct resource,
great! But... now when I run it on my device and change orientation I
don't see the same changes.  Any other hints?




-- 



Re: on orientation change, keep all objects, just change content view

by Wall-E » Wed, 30 Mar 2011 02:17:35 GMT


 Ok I got it to work by removing the
android:configChanges="orientation" in the manifest file.




-- 



Re: Re: on orientation change, keep all objects, just change content view

by Mark Murphy » Wed, 30 Mar 2011 02:19:19 GMT


 


Yes. If you have the default version in res/layout/main.xml, a
landscape version to override the default would go in
res/layout-land/main.xml.


Of course not. You specifically told Android not to perform any
changes, by using android:configChanges. If you want Android to
automatically apply the changes, by destroying and recreating your
activity, get rid of android:configChanges. Otherwise, you have to
make whatever changes you want in Java code.

Which is why you should not write your activities the way you did.
android:configChanges is to be used in fairly limited cases, and
there's nothing in either of your posts that suggests that your
activity fits one of those cases (e.g., uses a WebView, uses a
Camera).


Use onSaveInstanceState() and onRetainNonConfigurationInstance() to
pass data to the new activity from the old one, after you get rid of
android:configChanges.

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

_The Busy Coder's Guide to *Advanced* Android Development_ Version
1.9.2 Available!

-- 



Re: on orientation change, keep all objects, just change content view

by Wall-E » Wed, 30 Mar 2011 02:31:06 GMT


 Thanks Mark, after I made the fixed I noticed that when I changed
orientation the objects were not the same so I'll give
onSaveInstanceState() and onRetainNonConfigurationInstance() a shot.






-- 



Other Threads

1. Koi live wallpaper

Thank berats, bos.....

Btw, kalo apk dari pasar malem gini bukannya gak boleh di attached di
jalum yak ? CMIIW.



-SF-





> 

2. How to handle phone low memory situation more efficiently?

No one care about android performance or No one ever encounter
performance issue?
Could Google guys give me some ideas?



> 

3. Charging by computer or electrik outlet

4. antara magic n spica

5. Internal Files, Email Attachments

6. Change Hue on Image

7. I can't find my own application in the market