• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Fragments Displaying other Fragments

Hello,

So I am Very new to the entire android thing, and I'm currently working on developing a unique app. In doing so I am trying to find the best way to implement it and wanting to know if my topic is in fact possible. So for a bit more specifics this is what I am wanting to do but unsure if I can:

Consider an Activity with 2 Fragments we will call them Top_1 & Bottom_1, now Bottom_1 will remain on the bottom half of the screen at all times first appearing with Top_1. Through Button/Spinner Listener in Bottom_1 I want to be able to display different Fragments, such as Top_2, Top_3, Top_4 etc. all the while keeping Bottom_1 intact.

At this given moment I am just looking to see if this is possible to do, as I have created a two Fragment activity, and from what I learned I'm having difficulty grasping in how I would call to the other Fragments and have them replace the top.

Thanks for your consideration.
 
Yes indeed. It's why fragments were introduced - to make it possible to create modular, composite screens with dynamic content. It also allows great code reuse, and promotes good software architecture. Fragments also have a lifecycle very similar to Activities, and you can add them to the back stack - so the back button works, if you want that behaviour.
I think all this fits in with what you want to achieve. In fact I'm doing something very similar myself right at the moment, creating a screen which has distinct parts, which can vary, depending on the user input. It's possible to replace a container element with a different Fragment, dynamically. There are lots of code examples of how to do this.
Fragments are the way to go!
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones