Creating and using fragments
Sometimes normal layouts aren't dynamic enough or we may have to reuse sections of the UI and its related code.
Getting ready
To add fragments to our app we need to be targeting Android version 3.0 and above; for versions below that, we need to have installed the Xamarin.Android.Support.v4 package.
How to do it...
In order to make use of fragments in our apps, we need to create a new fragment type. Then, either in the layout or in the code, we can insert the fragments into their appropriate places in the UI. Let's take a look at the following steps:
- To make a master-detail app, we need a menu or list of items to select. For the menu fragment we are going to inherit from
ListFragment
, which is very similar toListActivity ...
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.