Kawaii Chan Kawaii Chan - 1 year ago 76
Android Question

Android navigation through multiple layouts

i have this app that i want to have a specific way of navigation. And so i made a research but i got confused. And i am begginer in android development.
i want to ask what kind of layout or anything i can use to achieve that. I dont search for super specific answer, just what is the thing that is doing the job i want. So there it is:

enter image description here

the blue block("choose a brand" view) has to be on that position at all times and only changing the text if needed. I want when one image button is clicked the whole green block with the image grid change into another xml layout. I want to call multiple layouts in the green block when i interact with the buttons of those layouts. Atm the green block is an

<include layout ="layout.xml"/>

I really apreciate any answer. Sorry if is basic but i really tried to find the thing i need but so far i see solutions that prevent me from using simple inflaters. Thanks in advance

Answer Source

You have to use fragments for this scenario.

You will have a LinearLayout where the first element will be your blue block. The second element will be a FrameLayout that you will change into the Fragment you need (usually it will have the ID container).

Create a Fragment and set the layout your layout.xml file. Create a second Fragment with the desired layout you would like to change the green block.

As you click on a imageButton you will have to change the current Fragment with the desired one. Here you will see how to send objects to fragments.

You can find here a way to switch between fragments. In the ft.replace method the first id is the FrameLayout you will use as a container(see above).

FragmentTransaction ft = getFragmentManager().beginTransaction(); 
ft.replace(R.id.container, new NewFragmentToReplace(), "NewFragmentTag"); 

Be careful when you import fragments. If you use the support package you will have to use getSupportFragmentManager();

Read more on the android developer about fragments

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download