Navigating between fragments

Fragments can be navigated through and back, like activities. Sometimes we have a layout that will be displayed when a user selects an option, and we want the back navigation to be as seamless as pressing the back button.

How to do it...

When it comes to navigation with fragments, we do not insert the fragments into the layout. Rather, we use an empty container layout. Then, at runtime, we insert the correct fragment:

  1. First, we are going to add a new layout for portrait view. Landscape will be the original two-pane layout, and the new portrait view will have the single pane, but with swapping (Resources/layout-port/Main.axml):
    <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" ...

Get Xamarin Mobile Development for Android Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.