Search code examples
androidandroid-activityslidingmenu

Android - Switching multiple layouts within single activity


I am developing application which requires many (more than 80) screen layouts (each layout having different image views, buttons, textviews and so on) and I have to be able to switch between them (upon button clicks). I am also using SlidingMenu so I would very much like to have only one Activity (I am currently using ActionBarActivity and the SlidingMenu serves as expandable navigation TreeView).

So my question is, what is the best practice to be able to switch between a lot of unique screen layouts within one activity ?


Solution

  • I suggest two ways:

    1) Use FrameLayout, and Fragment

    2) Use ViewFlipper in main.xml that in this one every child of ViewFliper is one of your 80 views like:

    <ViewFlipper ...>
    
    <!-- first view -->
    <LinearLayout ...>
    
    </LinearLayout>
    
    <!-- second view -->
    <LinearLayout ...>
    
    </LinearLayout>
    
    <!-- third view -->
    <LinearLayout ...>
    
    </LinearLayout>
    
    <!-- and so on -->
    
    </ViewFlipper>  
    

    Of course you can create 80 separate xml files and include them in ViewFlipper.