Reputation: 2051
Am I right in saying that using fragments in Android is the best way to handle the following scenario:
I have a main navigation view with some buttons on it. To better understand the navigation, it is a tourism app, so the main navigation view will have buttons like "Where to stay", "Where to Eat", "What to do" etc.
Clicking on e.g. "Where to stay" will take you to a sub-navigation page with more buttons like "Hotel", "B&B", "Caravan Site" etc.
Clicking on e.g. Hotel in the sub-navigation will show a list of Hotels in alphabetical order to you. Then you click on the hotel you like which will take you to a view with that hotels info on it.
This walkthrough will be pretty much identical for each section (Where to stay, Where to eat....)
Instead of creating many views each with its own content (so a view for Hotel A, a view for Hotel B etc), can I just create one view and swap content in and out using fragments?
Is this the best way to do this, or is there a better way? I have never done this before so any tutorials will be helpful as well.
Below is a image that might help explain the navigation.
Upvotes: 0
Views: 70
Reputation: 1126
Yes Fragments will be good for this.
You might get useful scenario here
As fragments might be dynamically added, get some information from android developer website, and you can download sample code for Fragment Basics from there.
I suggest you to learn maintaining Fragment state and it would be better if you just go through BackStack for Fragments
Upvotes: 0
Reputation: 118
Yes, Fragments is the Way to go, especially if you want to provide different Layouts for Phones and Tablets.
This http://developer.android.com/training/basics/fragments/index.html should be what your looking for, a guide how to handle Fragments, and how to build an UI with them.
Upvotes: 1