开发者

Two layouts to be loaded for single activity

开发者 https://www.devze.com 2023-03-26 07:38 出处:网络
I\'m having two layout.xml files. I need to load either one of the XML in a activity. Say initially i will be loading an activity using SetContentView and if a button click is done then i have to load

I'm having two layout.xml files. I need to load either one of the XML in a activity. Say initially i will be loading an activity using SetContentView and if a button click is done then i have to load another layout.xml file.

How can i do this?

This开发者_StackOverflow社区 change will be frequently done in the activity.


Say you have layout1.xml and layout2.xml

Change between them using

setContentView(layout1);

setContentView(layout2);

Careful

If you have buttons,textviews... that you reference using findViewById(), you must re-reference them again after calling setContentView()


call

setContentView(layout1);

and in your onClick() method, call

setContentView(layout2);    
0

精彩评论

暂无评论...
验证码 换一张
取 消