• Create Tabs Menu and Add Fragments for Book Categories in the Xamarin Android App using C# and Visual Studio

    by  • January 17, 2017 • Android with C# and .NET, Xamarin Mobile App Development • 0 Comments

    In this post, I’m going to explain, how we can add tabs menu in the Android App. In order to add tabs menu, we need fragments as well as each tab will load a separate fragment. So we’ll learn how to create and add Fragments as well. Earlier, we were loading all the books on a single Activity in a ListView. We customized the row layout, but all the books were displayed in a single list. This post will show you how you can show books of different categories in a separate list on a separate tab.

    First you need to create a folder named Fragments in your project and then create the Fragments classes including the BaseFragment with common code and then inherit the other Fragments from this BaseFragment. Add fragments classes

    Below you can find the code for BaseFragment and one other Fragment. The code for remaining child Fragments is almost the same except filtering by a different category. We’ll also add code on Github as a whole project, so you can get a complete picture and run the complete app on your computer.

    Code for Base Fragment

    Code for Child Fragment

    Now, you need to create the Fragment layouts.

    add fragments layouts

    The code for one fragment layout is given, while the layout for other fragments is same.

    Code Fragment Layout

    And finally, you need to update the code in the ViewBooks activity which we had already added and was showing a single list with all the books. Now it will show tabs and load Fragments in on click of each tab.

    Updated code for ViewBooksActivity

    Now after all these updates when you run the App and go to View Books activity, it will look something like this.

    How tabs looks like

    I hope you enjoyed it. Soon I’ll publish this project on Github so can view complete working code and try it at your end as well.




    Namecheap.com
    Avatar of admin

    About

    GetCodeSnippet.com provides you high quality Microsoft .NET development related articles, tutorials and sample code for ASP.NET, C#, VB.NET, AJAX, WCF, WPF, Web Services, Windows Services, SQL Server and other technologies.

    Leave a Reply