Skip to content Skip to sidebar Skip to footer

Activities Vs Fragments

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

Solution 1:

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

Post a Comment for "Activities Vs Fragments"