Home
Unlabelled
Create A Spinner In Xamarin Android
Create A Spinner In Xamarin Android
XAMARIN Android Development
Create A Spinner In Xamarin Android Application Using Visual Studio 2015 Update 3
Introduction
This article is about how to create a spinner application with textview in Xamarin Android application using Visual Studio 2015 update 3.
This article is about how to create a spinner application with textview in Xamarin Android application using Visual Studio 2015 update 3.
Requirements
- Visual Studio 2015 update 3
If you want develop the spinner application in xamarin android application, you should follow the below steps.
Step 1
Open the visual studio 2015 update 3 and click the File and NewProject and open the new window, it should be following shortcut keys(Ctrl+Shift+N)
Open the visual studio 2015 update 3 and click the File and NewProject and open the new window, it should be following shortcut keys(Ctrl+Shift+N)
Step 2
Now,open the New project and go to the Visual c# and click the Android then choose the BlankApp(Android). Now write application name and click the OK button.

Step 4
Now,open the project and go to solution explorer and click the Resource and click the Layout and click the Main.xaml.

Now,open the New project and go to the Visual c# and click the Android then choose the BlankApp(Android). Now write application name and click the OK button.
Step 4
Now,open the project and go to solution explorer and click the Resource and click the Layout and click the Main.xaml.
Step 5
Here, open the designer page and click the View and Toolbox and if you want some option, it is like that spinner and textview to drag and drop the method and build the design.
Here, open the designer page and click the View and Toolbox and if you want some option, it is like that spinner and textview to drag and drop the method and build the design.
Step 6
Now ,go to the Source build the XAML code.
Here,XAML code.
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
- <TextView
- android:text="@string/language_prompt"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/textView1" />
- <Spinner
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/spinner1"
- android:prompt="@string/language_prompt"/>
- </LinearLayout>
Now, go to Values and select to string.xml page and build code, it should be like that array's value.
Step 8
Here,write on string value. It is like items(c,c++,c#,ASP.NET
We can see that XML code.
- <?xml version="1.0" encoding="utf-8"?>
- <resources>
- <string name="language_prompt">Choose a Language</string>
- <string-array name="language_array">
- <item>C</item>
- <item>C++</item>
- <item>JAVA</item>
- <item>C#</item>
- <item>ASP.NET</item>
- <item>PERL</item>
- <item>PHP</item>
- <item>SQL</item>
- </string-array>
- </resources>
Step 9
Now,go to MainActivity.cs and fill and build the C sharp code.

Now,go to MainActivity.cs and fill and build the C sharp code.
- using System;
- using Android.App;
- using Android.Content;
- using Android.Runtime;
- using Android.Views;
- using Android.Widget;
- using Android.OS;
- using Android.Text;
- namespace SpinnerApp
- {
- [Activity(Label = "SpinnerApp", MainLauncher = true, Icon = "@drawable/icon")]
- public class MainActivity : Activity
- {
- protected override void OnCreate(Bundle bundle)
- {
- base.OnCreate(bundle);
- // Set our view from the "main" layout resource
- SetContentView(Resource.Layout.Main);
- //SetContentView(Resource.Layout.Main);
- Spinner spinner = FindViewById<Spinner>(Resource.Id.spinner1);
- spinner.ItemSelected += new EventHandler<AdapterView.ItemSelectedEventArgs>(spinner_ItemSelected);
- var adapter = ArrayAdapter.CreateFromResource(
- this, Resource.Array.language_array, Android.Resource.Layout.SimpleSpinnerItem);
- adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
- spinner.Adapter = adapter;
- }
- private void spinner_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e)
- {
- Spinner spinner = (Spinner)sender;
- string toast = string.Format("The Language is {0}", spinner.GetItemAtPosition(e.Position));
- Toast.MakeText(this, toast, ToastLength.Long).Show();
- }
- }
- }
Now, go to run the project, it should be follow the shortcut keys F5 and run Android mobile phone model(Nokia X).
Step 11
Here, you can see that output.
Here,you can choose the language.

Here,you can click the language and after that you see that final output.

Presented By:
Abdul Rauf
Create A Spinner In Xamarin Android
Reviewed by Unknown
on
1:41 AM
Rating: 5
Reviewed by Unknown
on
1:41 AM
Rating: 5


No comments:
Thanks