Skip to content

Instantly share code, notes, and snippets.

@Redth
Created October 12, 2010 23:24
Show Gist options
  • Select an option

  • Save Redth/623116 to your computer and use it in GitHub Desktop.

Select an option

Save Redth/623116 to your computer and use it in GitHub Desktop.
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
namespace MonoDroid.CustomList
{
[Activity(Label = "1 CustomList", MainLauncher = true)]
public class CustomList : Activity
{
CustomListAdapter listAdapter;
public CustomList(IntPtr handle)
: base(handle)
{
}
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
//Set the Activity's view to our list layout
SetContentView(Resource.layout.customlist);
//Create our adapter
listAdapter = new CustomListAdapter(this);
//Find the listview reference
var listView = FindViewById<ListView>(Resource.id.listView);
//Hook up our adapter to our ListView
listView.Adapter = listAdapter;
//Wire up the click event
listView.ItemClick += new EventHandler<ItemEventArgs>(listView_ItemClick);
}
void listView_ItemClick(object sender, ItemEventArgs e)
{
//Get our item from the list adapter
var item = this.listAdapter.GetItemAtPosition(e.Position);
//Make a toast with the item name just to show it was clicked
Toast.MakeText(this, item.Name + " Clicked!", ToastLength.Short).Show();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment