My application requires 2 screens and for this I have created two different XML
layout files using RelativeLayout
. One layout file loads whenever I run my Activity. Now I want to load the second layout on to the same Activity
, when user click on a button in OptionsMenu
and also when user press Back button the first screen loads instead of exiting the application. So that i don't need to create another Intent
in my application.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Ideally there should be two different activities present in your application. You can add or remove a view component in a view but if you are looking for two completely different screens then i would suggest you to go for a new activity.
I dint get what you meant by "and also when user press Bakc button the first screen loads instead of exiting the application"
If you dont want to show the first screen just finish() the activity.
回答2:
Did you try re-calling the setContentView?
Or you may prefer using the ViewFlipper,
Good example here.
回答3:
I would suggest a rather simpler means.
Put both your layouts in the single XML and show/gone them appropriately as need be. I dont think u need anything more complicated :-)