Xamarin.Android shows how the ListViews can be added to every tab control. For more details, visit my Xamarin.Android related articles.
In this module, I have added some tabs and put some listviews on every tab page. Then, I set the icon of the app manually that makes it easy to identify the proper implementation of the app.
Add an icon file of Android app by putting the png file as "Icon.png" .
Use this code of Main.axml.
I have added one textview and one listview control . That will work based on the selection of tab.
Step 3
Use this code for MainActivity.cs.
- using System;
- using Android.App;
- using Android.Content;
- using Android.Runtime;
- using Android.Views;
- using Android.Widget;
- using Android.OS;
- using Android.Graphics;
- using System.Collections.Generic;
-
- namespace SatyapraashTabs
- {
- [Activity(Label = "SatyapraashTabs", MainLauncher = true, Icon = "@drawable/icon")]
- public class MainActivity : Activity
- {
- private TextView textView;
-
- private ListView listnames1;
- private ListView listnames2;
- private ListView listnames3;
- private ListView listnames4;
-
- private List<string> itemlist1;
- private List<string> itemlist2;
- private List<string> itemlist3;
- private List<string> itemlist4;
- protected override void OnCreate(Bundle bundle)
- {
- base.OnCreate(bundle);
- SetContentView(Resource.Layout.Main);
- textView = FindViewById<TextView>(Resource.Id.textView1);
-
- ActionBar.NavigationMode = ActionBarNavigationMode.Tabs;
-
-
- AddTab(Resource.Drawable.article, "Article");
- AddTab(Resource.Drawable.blog, "Blog");
- AddTab(Resource.Drawable.news, "News");
- AddTab(Resource.Drawable.award, "Awards");
-
- }
-
- private void AddTab(int tabimg, string tabText)
- {
- ActionBar.Tab tab = ActionBar.NewTab();
- tab.SetText(tabText);
- tab.SetIcon(tabimg);
- tab.TabSelected += OnTabSelected;
- ActionBar.AddTab(tab);
- }
- private void OnTabSelected(object sender, ActionBar.TabEventArgs args)
- {
- var CurrentTab = (ActionBar.Tab)sender;
-
- if (CurrentTab.Position == 0)
- {
-
- textView.Text = "Article Tab Selected";
- textView.SetBackgroundColor(Color.Red);
- listnames1 = FindViewById<ListView>(Resource.Id.listview);
-
-
- LinearLayout mainLayout = FindViewById<LinearLayout>(Resource.Id.linearlayout2);
- mainLayout.SetBackgroundColor(Color.RoyalBlue);
-
- itemlist1 = new List<string>();
- itemlist1.Add("Create App Using Xamarin.Android Using C# - Part Four");
- itemlist1.Add("Introduction To SQL Operations Studio And Connecting It With SQL Server");
- itemlist1.Add("Client Side Routing Using Angular In MVC");
- itemlist1.Add("Partial View In ASP.NET MVC Using Entity Framework");
- ArrayAdapter<string> adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, itemlist1);
- listnames1.Adapter = adapter;
- listnames1.ItemClick += Listnames1_ItemClick;
-
- }
- else if (CurrentTab.Position == 1)
- {
-
- textView.Text = "Blog Tab Selected";
- textView.SetBackgroundColor(Color.OrangeRed);
- listnames2 = FindViewById<ListView>(Resource.Id.listview);
- LinearLayout mainLayout = FindViewById<LinearLayout>(Resource.Id.linearlayout2);
- mainLayout.SetBackgroundColor(Color.Blue);
- itemlist2 = new List<string>();
- itemlist2.Add("Boost Your Career Through C# Corner");
- itemlist2.Add("Google Map GPS Locator Using MVC And BootBox - Part Thirteen");
- itemlist2.Add("Google Maps- Route Direction Information Between Source And Destination");
- itemlist2.Add("Google Maps Travelling Mode Using Bootstrap In ASP.NET MVC - PART Seven");
- ArrayAdapter<string> adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, itemlist2);
- listnames2.Adapter = adapter;
- listnames2.ItemClick += Listnames2_ItemClick;
-
-
- }
- else if (CurrentTab.Position == 2)
- {
- var textView = FindViewById<TextView>(Resource.Id.textView1);
- textView.Text = "News Tab Selected";
- textView.SetBackgroundColor(Color.RoyalBlue);
- listnames3 = FindViewById<ListView>(Resource.Id.listview);
- LinearLayout mainLayout = FindViewById<LinearLayout>(Resource.Id.linearlayout2);
- mainLayout.SetBackgroundColor(Color.Orchid);
- itemlist3 = new List<string>();
- itemlist3.Add("C# Corner Android App v0.5.7 Released");
- itemlist3.Add("Google Releases ARCore Developer Preview 2");
- itemlist3.Add("Artificial Intelligence Microsoft Launches AI Platform And AI School Silently");
- itemlist3.Add("Amazon Launches A New Test Simulator (Beta) for Alexa Skills");
- ArrayAdapter<string> adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, itemlist3);
- listnames3.Adapter = adapter;
- listnames3.ItemClick += Listnames3_ItemClick;
- }
- else if (CurrentTab.Position == 3)
- {
- var textView = FindViewById<TextView>(Resource.Id.textView1);
- textView.Text = "Awards Tab Selected";
- textView.SetBackgroundColor(Color.Blue);
- listnames4 = FindViewById<ListView>(Resource.Id.listview);
- LinearLayout mainLayout = FindViewById<LinearLayout>(Resource.Id.linearlayout2);
- mainLayout.SetBackgroundColor(Color.Olive);
- itemlist4 = new List<string>();
- itemlist4.Add("The Month of April 2017 Winners Announced");
- itemlist4.Add("2017 First Half of the Year MVPs Announced ");
- itemlist4.Add("Microsoft Announces New AI MVP Award Category");
- itemlist4.Add("Xamarin MVPs Join Microsoft MVP Program");
- ArrayAdapter<string> adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, itemlist4);
- listnames4.Adapter = adapter;
- listnames4.ItemClick += Listnames4_ItemClick;
- }
- }
- private void Listnames1_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
- {
- Toast.MakeText(this, e.Position.ToString(), ToastLength.Long).Show();
- Toast.MakeText(this, "You Clicked Article at " + itemlist1[e.Position], ToastLength.Long).Show();
- }
- private void Listnames2_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
- {
- Toast.MakeText(this, e.Position.ToString(), ToastLength.Long).Show();
- Toast.MakeText(this, "You Clicked Blog at " + itemlist2[e.Position], ToastLength.Long).Show();
- }
- private void Listnames3_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
- {
- Toast.MakeText(this, e.Position.ToString(), ToastLength.Long).Show();
- Toast.MakeText(this, "You Clicked News at " + itemlist3[e.Position], ToastLength.Long).Show();
- }
- private void Listnames4_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
- {
- Toast.MakeText(this, e.Position.ToString(), ToastLength.Long).Show();
- Toast.MakeText(this, "You Clicked Awards at " + itemlist4[e.Position], ToastLength.Long).Show();
- }
- }
- }
Code Description
For setting the image icon and text, add the code snippet as below.
- protected override void OnCreate(Bundle bundle)
- {
- base.OnCreate(bundle);
- SetContentView(Resource.Layout.Main);
- textView = FindViewById<TextView>(Resource.Id.textView1);
-
- ActionBar.NavigationMode = ActionBarNavigationMode.Tabs;
-
-
- AddTab(Resource.Drawable.article, "Article");
- AddTab(Resource.Drawable.blog, "Blog");
- AddTab(Resource.Drawable.news, "News");
- AddTab(Resource.Drawable.award, "Awards");
-
- }
-
- private void AddTab(int tabimg, string tabText)
- {
- ActionBar.Tab tab = ActionBar.NewTab();
- tab.SetText(tabText);
- tab.SetIcon(tabimg);
- tab.TabSelected += OnTabSelected;
- ActionBar.AddTab(tab);
- }
For setting only image icon, add the code snippet given below.
- protected override void OnCreate(Bundle bundle)
- {
- base.OnCreate(bundle);
- SetContentView(Resource.Layout.Main);
- textView = FindViewById<TextView>(Resource.Id.textView1);
-
- ActionBar.NavigationMode = ActionBarNavigationMode.Tabs;
-
-
- AddTab(Resource.Drawable.article);
- AddTab(Resource.Drawable.blog);
- AddTab(Resource.Drawable.news);
- AddTab(Resource.Drawable.award);
-
- }
-
- private void AddTab(int tabimg)
- {
- ActionBar.Tab tab = ActionBar.NewTab();
-
- tab.SetIcon(tabimg);
- tab.TabSelected += OnTabSelected;
- ActionBar.AddTab(tab);
- }
For setting the text only for tab, use this code.
- protected override void OnCreate(Bundle bundle)
- {
- base.OnCreate(bundle);
- SetContentView(Resource.Layout.Main);
- textView = FindViewById<TextView>(Resource.Id.textView1);
-
- ActionBar.NavigationMode = ActionBarNavigationMode.Tabs;
-
-
- AddTab("Article");
- AddTab("Blog");
- AddTab("News");
- AddTab("Awards");
-
- }
-
- private void AddTab(string tabText)
- {
- ActionBar.Tab tab = ActionBar.NewTab();
- tab.SetText(tabText);
- tab.TabSelected += OnTabSelected;
- ActionBar.AddTab(tab);
- }
First, I declared some variables using which we can access the value of control assigned to it.
- private TextView textView;
-
- private ListView listnames1;
- private ListView listnames2;
- private ListView listnames3;
- private ListView listnames4;
-
- private List<string> itemlist1;
- private List<string> itemlist2;
- private List<string> itemlist3;
- private List<string> itemlist4;
Then, in OnCreate() method, I added the tabs to Action Bar.
- ActionBar.NavigationMode = ActionBarNavigationMode.Tabs;
-
-
- AddTab("Article");
- AddTab("Blog");
- AddTab("News");
- AddTab("Awards");
Set the activity content from the layout resource.
- SetContentView(Resource.Layout.Main);
This method will be called when the activity is started.
- textView = FindViewById<TextView>(Resource.Id.textView1);
This textview will take the value of textview1 control id of TextView control class using
FindViewById<TextView>.
- ActionBar.NavigationMode = ActionBarNavigationMode.Tabs;
We can set the navigation mode on action bar.
- private void AddTab(string tabText)
- {
- ActionBar.Tab tab = ActionBar.NewTab();
- tab.SetText(tabText);
- tab.TabSelected += OnTabSelected;
- ActionBar.AddTab(tab);
- }
Here, I added the AddTab() method to add the tab text names as well as OnTabSelected event will be fired as per the selection of tabs.
- private void OnTabSelected(object sender, ActionBar.TabEventArgs args)
- {
- var CurrentTab = (ActionBar.Tab)sender;
-
- if (CurrentTab.Position == 0)
- {
-
- textView.Text = "Article Tab Selected";
- textView.SetBackgroundColor(Color.Red);
- listnames1 = FindViewById<ListView>(Resource.Id.listview);
-
-
- LinearLayout mainLayout = FindViewById<LinearLayout>(Resource.Id.linearlayout2);
- mainLayout.SetBackgroundColor(Color.RoyalBlue);
-
- itemlist1 = new List<string>();
- itemlist1.Add("Create App Using Xamarin.Android Using C# - Part Four");
- itemlist1.Add("Introduction To SQL Operations Studio And Connecting It With SQL Server");
- itemlist1.Add("Client Side Routing Using Angular In MVC");
- itemlist1.Add("Partial View In ASP.NET MVC Using Entity Framework");
- ArrayAdapter<string> adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, itemlist1);
- listnames1.Adapter = adapter;
- listnames1.ItemClick += Listnames1_ItemClick;
-
- }
- else if (CurrentTab.Position == 1)
- {
-
- textView.Text = "Blog Tab Selected";
- textView.SetBackgroundColor(Color.OrangeRed);
- listnames2 = FindViewById<ListView>(Resource.Id.listview);
- LinearLayout mainLayout = FindViewById<LinearLayout>(Resource.Id.linearlayout2);
- mainLayout.SetBackgroundColor(Color.Blue);
- itemlist2 = new List<string>();
- itemlist2.Add("Boost Your Career Through C# Corner");
- itemlist2.Add("Google Map GPS Locator Using MVC And BootBox - Part Thirteen");
- itemlist2.Add("Google Maps- Route Direction Information Between Source And Destination");
- itemlist2.Add("Google Maps Travelling Mode Using Bootstrap In ASP.NET MVC - PART Seven");
- ArrayAdapter<string> adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, itemlist2);
- listnames2.Adapter = adapter;
- listnames2.ItemClick += Listnames2_ItemClick;
-
-
- }
- else if (CurrentTab.Position == 2)
- {
- var textView = FindViewById<TextView>(Resource.Id.textView1);
- textView.Text = "News Tab Selected";
- textView.SetBackgroundColor(Color.RoyalBlue);
- listnames3 = FindViewById<ListView>(Resource.Id.listview);
- LinearLayout mainLayout = FindViewById<LinearLayout>(Resource.Id.linearlayout2);
- mainLayout.SetBackgroundColor(Color.Orchid);
- itemlist3 = new List<string>();
- itemlist3.Add("C# Corner Android App v0.5.7 Released");
- itemlist3.Add("Google Releases ARCore Developer Preview 2");
- itemlist3.Add("Artificial Intelligence Microsoft Launches AI Platform And AI School Silently");
- itemlist3.Add("Amazon Launches A New Test Simulator (Beta) for Alexa Skills");
- ArrayAdapter<string> adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, itemlist3);
- listnames3.Adapter = adapter;
- listnames3.ItemClick += Listnames3_ItemClick;
- }
- else if (CurrentTab.Position == 3)
- {
- var textView = FindViewById<TextView>(Resource.Id.textView1);
- textView.Text = "Awards Tab Selected";
- textView.SetBackgroundColor(Color.Blue);
- listnames4 = FindViewById<ListView>(Resource.Id.listview);
- LinearLayout mainLayout = FindViewById<LinearLayout>(Resource.Id.linearlayout2);
- mainLayout.SetBackgroundColor(Color.Olive);
- itemlist4 = new List<string>();
- itemlist4.Add("The Month of April 2017 Winners Announced");
- itemlist4.Add("2017 First Half of the Year MVPs Announced ");
- itemlist4.Add("Microsoft Announces New AI MVP Award Category");
- itemlist4.Add("Xamarin MVPs Join Microsoft MVP Program");
- ArrayAdapter<string> adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, itemlist4);
- listnames4.Adapter = adapter;
- listnames4.ItemClick += Listnames4_ItemClick;
- }
- }
- private void Listnames1_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
- {
- Toast.MakeText(this, e.Position.ToString(), ToastLength.Long).Show();
- Toast.MakeText(this, "You Clicked Article at " + itemlist1[e.Position], ToastLength.Long).Show();
- }
- private void Listnames2_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
- {
- Toast.MakeText(this, e.Position.ToString(), ToastLength.Long).Show();
- Toast.MakeText(this, "You Clicked Blog at " + itemlist2[e.Position], ToastLength.Long).Show();
- }
- private void Listnames3_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
- {
- Toast.MakeText(this, e.Position.ToString(), ToastLength.Long).Show();
- Toast.MakeText(this, "You Clicked News at " + itemlist3[e.Position], ToastLength.Long).Show();
- }
- private void Listnames4_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
- {
- Toast.MakeText(this, e.Position.ToString(), ToastLength.Long).Show();
- Toast.MakeText(this, "You Clicked Awards at " + itemlist4[e.Position], ToastLength.Long).Show();
- }
In the OnTabSelected event, I assigned the properties of textview text name as well as color. These will be changed as per the selection of tabs and different listview names will be shown. On the selection of listview, it will show the position of listview in array as well as it shows the text or name of listview as per selection of user. By default, the start position of listview in tabbed page will start from 0.
Here, I declared one local variable. Based on the selection of tab in ActionBar, the value will be assigned to this local variable.
- var CurrentTab = (ActionBar.Tab)sender;
If I select the first tab, then the below code will be executed.
- if (CurrentTab.Position == 0)
- {
-
- textView.Text = "Article Tab Selected";
- textView.SetBackgroundColor(Color.Red);
- listnames1 = FindViewById<ListView>(Resource.Id.listview);
-
-
- LinearLayout mainLayout = FindViewById<LinearLayout>(Resource.Id.linearlayout2);
- mainLayout.SetBackgroundColor(Color.RoyalBlue);
-
- itemlist1 = new List<string>();
- itemlist1.Add("Create App Using Xamarin.Android Using C# - Part Four");
- itemlist1.Add("Introduction To SQL Operations Studio And Connecting It With SQL Server");
- itemlist1.Add("Client Side Routing Using Angular In MVC");
- itemlist1.Add("Partial View In ASP.NET MVC Using Entity Framework");
- ArrayAdapter<string> adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, itemlist1);
- listnames1.Adapter = adapter;
- listnames1.ItemClick += Listnames1_ItemClick;
-
- }
I assigned the listname click event of listview for the first tab.
- private void Listnames1_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
- {
- Toast.MakeText(this, e.Position.ToString(), ToastLength.Long).Show();
- Toast.MakeText(this, "You Clicked Article at " + itemlist1[e.Position], ToastLength.Long).Show();
- }
Then, it will show the position of listname of listview as well as the listname text value.
Like this, we can add other tabs' functionaity.
ActionBar
The Action Bar includes support for adding tabbed interfaces in Android 4.0. The following screenshot shows an example of such an interface.To create tabs in the Action Bar, we first need to set its NavigationMode property to support tabs. In Android 4, an ActionBar property is available on the Activity class, which we can use to set the NavigationMode .
- ActionBar.NavigationMode = ActionBarNavigationMode.Tabs;
Once this is done, we can create a tab by calling the NewTab method on the Action Bar. With this tab instance, we can call the SetText and SetIcon methods to set the tab's label text and icon.
- ActionBar.Tab tab = ActionBar.NewTab();
- tab.SetText(tabText);
- tab.SetIcon(Resource.Drawable.Icon);
- tab.TabSelected += OnTabSelected;
- ActionBar.AddTab(tab);
Before we can add the tab however, we need to handle the TabSelected event. In this handler, we can create the content for the tab. Action Bar tabs are designed to work with
Fragments, which are classes that represent a portion of the user interface in an Activity.
ActionBar Tabs
The action bar is an Android UI pattern that is used to provide a consistent user interface for key features such as tabs, application identity, menus, and search. In Android 3.0 (API level 11), Google introduced the ActionBar APIs to the Android platform. The ActionBar APIs introduce UI themes to provide a consistent look and feel and classes that allow for tabbed user interfaces. This guide discusses how to add Action Bar tabs to a Xamarin.Android application. It also discusses how to use the Android Support Library v7 to backport ActionBar tabs to Xamarin.Android applications targeting Android 2.1 to Android 2.3.
The action bar tries to display all of its tabs concurrently and make all the tabs equal in size based on the width of the widest tab label.
Each tab in the action bar should be associated with a fragment. When the user selects a tab, the application will display the fragment that is associated with the tab. The ActionBar is not responsible for displaying the appropriate fragment to the user. Instead, the ActionBar will notify an application about state changes in a tab through a class that implements the ActionBar.ITabListener interface. This interface provides three callback methods that Android will invoke when the state of the tab changes,
OnTabSelected
This method is called when the user selects the tab. It should display the fragment.
OnTabReselected
This method is called when the tab is already selected but is selected again by the user. This callback is typically used to refresh/update the displayed fragment.
OnTabUnselected
This method is called when the user selects another tab. This callback is used to save the state in the displayed fragment before it disappears.
Xamarin.Android wraps the ActionBar.ITabListener with events on the ActionBar.Tab class. Applications may assign event handlers to one or more of these events. There are three events (one for each method in ActionBar.ITabListener) that an action bar tab will raise,
- TabSelected
- TabReselected
- TabUnselected
The ActionBar is native to Android 3.0 (API level 11) and higher and is available to any Xamarin.Android application that targets this API as a minimum.
In the OnCreate method of an Activity –
before initializing any UI widgets – an application must set the NavigationMode on the ActionBar to ActionBar.NavigationModeTabs
Create a new tab using ActionBar.NewTab().Assign event handlers or provide a custom ActionBar.ITabListener implementation that will respond to the events that are raised when the user interacts with the ActionBar tabs.Add the tab that was created in the previous step to the ActionBar.
Event Handlers and ActionBar.ITabListener
Applications should use event handlers and ActionBar.ITabListener for different scenarios. Event handlers do offer a certain amount of syntactic convenience; they save you from having to create a class and implement ActionBar.ITabListener. This convenience does come at a cost – Xamarin.Android performs this transformation for you, creating one class and implementing ActionBar.ITabListener for you. This is fine when an application has a limited number of tabs.
When dealing with many tabs, or sharing common functionality between ActionBar tabs, it can be more efficient in terms of memory and performance to create a custom class that implements ActionBar.ITabListener, and sharing a single instance of the class. This will reduce the number of GREF's that a Xamarin.Android application is using.
Overview
A tabbed user interface in a Xamarin.Android using the ActionBar. We covered how to add tabs to the ActionBar and an Activity can interact with tab events via the ActionBar.ITabListener interface. We also saw how the Android Support Library v7 AppCompat component backports the ActionBar tabs to older versions of Android.
ListView
A ListView consists of the following parts,
Rows – The visible representation of the data in the list.
Adapter – A non-visual class that binds the data source to the list view.
Fast Scrolling – A handle that lets the user scroll the length of the list.
Section Index – A user interface element that floats over the scrolling rows to indicate where in the list the current rows are located. The primary classes used to display ListViews are shown here:
ListView – user interface element that displays a scrollable collection of rows. On phones it usually uses up the entire screen (in which case, the ListActivity class can be used) or it could be part of a larger layout on phones or tablet devices.
View – a View in Android can be any user interface element, but in the context of a ListView it requires a View to be supplied for each row.
BaseAdapter – Base class for Adapter implementations to bind a ListView to a data source.
ArrayAdapter – Built-in Adapter class that binds an array of strings to a ListView for display. The generic ArrayAdapter<T> does the same for other types.
CursorAdapter – Use CursorAdapter or SimpleCursorAdapter
to display data based on an SQLite query.
To add rows to a ListView you need to add it to your layout and implement an IListAdapter with methods that the ListView calls to populate itself. Android includes built-in ListActivity and ArrayAdapter classes that you can use without defining any custom layout XML or code. The ListActivity class automatically creates a ListView and exposes a ListAdapter property to supply the row views to display via an adapter.The built-in adapters take a view resource ID as a parameter that gets used for each row.
To respond to user touches there needs to be one more method implemented in the ListActivity – OnListItemClick – like this.
ArrayAdapter<string> is great because of its simplicity, but it's extremely limited. However, often times you have a collection of business entities, rather than just strings that you want to bind. For example, if your data consists of a collection of Employee classes, then you might want the list to just display the names of each employee. To customize the behavior of a ListView to control what data is displayed you must implement a subclass of BaseAdapter overriding the following four items,
Count – To tell the control how many rows are in the data.
GetView – To return a View for each row, populated with data. This method has a parameter for the ListView to pass in an existing, unused row for re-use.
GetItemId – Return a row identifier (typically the row number, although it can be any long value that you like).
this[int] indexer – To return the data associated with a particular row number.
Using the custom adapter is similar to the built-in ArrayAdapter, passing in a context and the string[] of values to display.Fast Scrolling helps the user to scroll through long lists by providing an additional 'handle' that acts as a scroll bar to directly access a part of the list.Causing the fast scrolling handle to appear is as simple as setting the FastScrollEnabled property to true,
- ListView.FastScrollEnabled = true;
A section index provides additional feedback for users when they are fast-scrolling through a long list – it shows which 'section' they have scrolled to. To cause the section index to appear the Adapter subclass must implement the ISectionIndexer interface to supply the index text depending on the rows being displayed.
To implement ISectionIndexer you need to add three methods to an adapter,
GetSections – Provides the complete list of section index titles that could be displayed. This method requires an array of Java Objects so the code needs to create a Java.Lang.Object[] from a .NET collection. In our example it returns a list of the initial characters in the list as Java.Lang.String .
GetPositionForSection – Returns the first row position for a given section index.
GetSectionForPosition – Returns the section index to be displayed for a given row.
OUTPUT
Both Icon and text for Tab
Only Icon For Tab
Only Text For Tab
Setting of Icon of Android App
Gif image for better understanding including both icon and text....
SUMMARY
- What is actionbar.
- What is actionbar tabs.
- How to set image and text in tab.
- Listview functionality in individual tabbed page.
<<Click here for previous part