Repository navigation
Expand file tree
/
Copy pathMainActivity.cs
More file actions
54 lines (43 loc) · 1.66 KB
/
Copy pathMainActivity.cs
File metadata and controls
54 lines (43 loc) · 1.66 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
namespace DemoListView.Android
{
[Activity(Label = "DemoListView.Android", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
int count = 1;
private string[] _listaItems;
private ListView _myLista;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
_myLista = FindViewById<ListView>(Resource.Id.listView1);
Button button = FindViewById<Button>(Resource.Id.MyButton);
_listaItems = new string[]//Llenamos nuestra lista
{
"Xamarin.Android",
"blog's javierflo95",
"Microsoft",
"Millonarios",
"Colombia",
"Bogotá",
"Mexico"
};
//Mostramos nuestra lista
_myLista.Adapter = new ArrayAdapter<String>(this, Android.Resource.Layout.ListaItems, _listaItems);
_myLista.ItemClick += _myLista_ItemClick;//Creamos el metodo para capturar el item seleccionado
button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); };
}
void _myLista_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
{
var _mensaje = _listaItems[e.Position];//Obtenemos el item seleccionado
Toast.MakeText(this, _mensaje, ToastLength.Short).Show();//Mostramos el item
}
}
}