Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

two different layouts for one activity

Tags:

Is it possible to have two different layouts for different cases in the same activity or do I have to use intent to call another activity with a different layout

like image 693
Ankush Avatar asked Oct 25 '12 07:10

Ankush


People also ask

Can one activity have multiple layouts?

You can use as many layouts as possible for a single activity but obviously not simultaneously. You can use something like: if (Case_A) setContentView(R. layout.

Can you use a same XML layout for 2 different activities?

Yes you can! I had multiple activities inflate the same layout but they save different shared preferences. @Override protected void onCreate(Bundle savedInstanceState) { super. onCreate(savedInstanceState); setContentView(R.

What is multiple layout?

A multi-layout document contains multiple documents, each in its own layout, creating a "book" of documents. Each layout functions as a separate document, with its own grouping, page setup, and so on, but the layouts are generated into a single PDF document.


2 Answers

Yes its possible. You can use as many layouts as possible for a single activity but obviously not simultaneously. You can use something like:

if (Case_A)   setContentView(R.layout.layout1);  else if (Case_B)   setContentView(R.layout.layout2); 

and so on...

like image 84
Ankush Avatar answered Sep 30 '22 07:09

Ankush


Yes this is also possible with switch case

I already tried this code....

switch (condition) {         case 1:       setContentView(R.layout.layout1);                  break;         case 2:       setContentView(R.layout.layout2);                  break;         case 3:       setContentView(R.layout.layout3);                  break;          default:      setContentView(R.layout.main);                  break;     } 
like image 32
Arvind Kanjariya Avatar answered Sep 30 '22 06:09

Arvind Kanjariya