I'm trying to design an application where the main mode of navigation through the application's several primary screens uses Tabs. I've basically copied the approach shown in the tutorial here: http://www.androidhive.info/2013/10/android-tab-layout-with-swipeable-views-1/
However, on some of these screens there are clickable elements that are supposed to kick off a full-screen page (the tabs should no longer at the top of the page). I've been able to get this working by creating a new activity for the new screen, but I believe I want to use a fragment for the new screen because in a tablet layout, I want the new screen to appear beside the main screen rather than replacing it. I haven't been successful doing this. If anyone can give examples or pointers on how to get a single activity to run fragments with tab-based navigation and other fragments that that don't have the tab navigation.
In a similar vein, I also have a settings screen accessible from the Options Menu. Are settings screens like this typically done as activities or fragments?
Thanks in advance.
You have to design your application in two ways.
Firstly you should know if you are running big device (tablet) or smaller one (smartphone).
You could make that by preparing two different layouts, one layout in layouts resource folder for smartphone and second layout in layout-xlarge resource folder for bigger devices.
In smaller layout make only one container for one fragment (list fragment for example). In bigger layout in layout-xlarge folder you coul have two containers one for fragment with list and second for fragment with content.
In onCreate method you could see if you are using multi pane layout or not.
If your secod pane in bigger layout is for example R.id.right_panel. You just make findViewById(R.id.right_panel) and if this is null, you know that you are not running multi pane.
Now if you are in multi pane, pressing item on the list should notify activity, and activity should change/replace right fragment with another one.
If you are not in multi pane, pressing item on the list should open new activity with only one fragment of content.
There are many tutorials of this of simmilar solutions like link or link
Regards
Related
I'm about to make my first Android application and I am currently reading about activities and fragments. I intend to use the Lollipop navigation drawer feature to load different screens in my application for different features. Like settings, About, Add new x, browse x, etc. Should my nav drawer be loading different activities for each item click or loading a new fragment?
All my screens will have the same style associated with them, but will have obviously much different content.
If I load a new activity, do I "lose" the nav drawer to the side? or is it always present as I want it to be accessible from any screen in the application.
I am quite unfamiliar with the Android system so far, but no matter what I choose do I need to use an intent to launch either of these. A real lay mans explanation would be greatly appreciated.
Thanks
EDIT: Within one of my screens I hope to use a tab system and have it change.
This is a mockup I have designed, as you can see I would like the nav drawer to be used from this screen but also allow the switching of 3 different tabs, within the Add new timetable screen.
How would I go about having a tab at the top and then 3 different (linked) screens under it. This would be the deepest level I would go. Every other screen would just be one screen, no tabs.
Activity typically takes the whole screen, so yes, if you launch an Activity, you will temporarily "lose" everything that's placed in other activities.
Fragments, on the other hand, can be stuffed to smaller areas, and you can have several fragments on the screen at once.
What is the best way to develop an android app with multiple screen content,
changing it with an drawer layout like the picture. How can I do that? By using
fragments with one activity and change each fragment by old fragment, or choose another technique?
Now i'm using one activity and replacing fragments.
Thanks in advance.
If the format of all the screens is the same, with essentially the same layout. Then you would only need one fragment that is updated based on which item in the drawer was selected.
If the screens are different then the original approach with multiple fragments and one activity is recommended.
I'm porting an iPhone+iPad app to Android. It uses a Split View Controller for tablets which in Android lingo allows you to present two Activities side by side simultaneously (Edit: Android only allows one Activity on screen as mentioned by #commonsware below. The next best thing is to use fragments, but the Action Bar can only exist at the Activity level, meaning it will have to expand the entire width of the screen. It wonder if a Split Activity Controller will be coming to the Android Platform.)
The tablet landscape layout has a fixed left pane for statistics that never changes. The right hand pane functions just like the phone version of the app. Transitions occur exclusively on the right hand pane. i.e. the whole screen doesn't slide when changing activities, only the right pane. How would you recommend implementing this in Android?
Should I use a single activity and manually perform transitions between fragments in the right panel? This app has 25 screens and will have an alternate layout for phones, so I'm trying to plan ahead and do this right the first time :) Thanks for your help!
It uses a Split View Controller for tablets which in Android lingo allows you to present two Activities side by side simultaneously.
No. In "Android lingo", you cannot "present two Activities side by side simultaneously". You can present two fragments side by side simultaneously.
How would you recommend implementing this in Android?
Use fragments. Use a FragmentTransaction to replace the right-hand fragment as needed based on user input. Your overall activity layout could have a horizontal LinearLayout (with android:layout_weight to control the sizes for the left and right sides), with a <fragment> element for the left and a FrameLayout for the right.
Should I use a single activity and manually perform transitions between fragments in the right panel?
Yes, to achieve what you ask for.
I'm trying to make application for tablet with Android 2.3 with this kind of design:
Screenshot http://techpcnews.com/wp-content/uploads/2011/11/System-Mechanic-Free-10.6.2.7-550x411.jpg
Left menu on the left to navigate between functionalities. But this left menu also must have some indicators dependent on what user made in some right site pages (e.g. how many searches he had or how many info he have).
I don't know how to make this. I thought about Tabs with content made of Views. But then ActivityTab has a lot of code inside and i don't thing this is good idea overall (but at the same time it's good because one page have easy connetion with another page).
You will want to use fragments to solve this. the left pane will be one fragment and the right pane another. Than you use the activity that the fragments reside in to send messages between the fragments. So the left pane will till the activity to till the right pane to load certain content.
Here is a great example:
http://developer.android.com/resources/samples/HoneycombGallery/index.html
Can anyone help me with finding the entry point into a fragment based app? I am having an app with multiple activites. For small resolution devices one of he activities is loaded at startup, in this case a menu. This activity is declared as "launcher" in the manifest.
On a high resolution device I do not want to display the menu but all other activities should be displayed as fragments at the same time. For this I have declared a new layout in a layout-w1000dp-h720dp folder.
However from the manifest file it is still the menu which is loaded at startup and not this new layout with multiple fragments. So my app crashes at startup because it is trying to launch the menu but with the new layout with multiple fragments...
What am I doing wrong? Wow can the manifest file work together with this new layout?
I have attached an image how the app should look on a large screen device with the four fragments/activities.
Could you post the exact error you're getting? The entry point for your app would be the Activity. Since your app is based around fragments, you could have one Activity that holds the four Fragments you displayed above. Your Manifest doesn't actually need anything extra to indicate that. I'm also guessing that you have XML layouts premade for the Fragments. If so, go to the layout of your Activity and specify the four fragments.
You would launch a single Activity, which then initializes your Fragments, and adds them in a FragmentTransaction.