two different layouts for one activity

后端 未结 5 1299
春和景丽
春和景丽 2020-12-08 15:57

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 di

5条回答
  •  我在风中等你
    2020-12-08 16:12

    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;
        }
    

提交回复
热议问题