Question

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.

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top