-
Notifications
You must be signed in to change notification settings - Fork 252
/
spinner.txt
31 lines (26 loc) · 1.14 KB
/
spinner.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/spinner1" />
//Define Spinner
Spinner spinner = FindViewById<Spinner>(Resource.Id.spinner1);
// dfeine data set
List<string> scaleNames = new List<string>();
scaleNames.Add("Developer");
scaleNames.Add("Admins");
scaleNames.Add("Desginner");
//asgin dataset
var scaleAdapter = new ArrayAdapter<string>(
this, Android.Resource.Layout.SimpleSpinnerItem, scaleNames);
scaleAdapter.SetDropDownViewResource
(Android.Resource.Layout.SimpleSpinnerDropDownItem);
spinner.Adapter = scaleAdapter;
// button click evnet
spinner.ItemSelected += new EventHandler<AdapterView.ItemSelectedEventArgs>(spinner_ItemSelected);
//spinner click
private void spinner_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e)
{
Spinner spinner = (Spinner)sender;
string toast = string.Format("The planet is {0}", spinner.GetItemAtPosition(e.Position));
Toast.MakeText(this, toast, ToastLength.Long).Show();
}