Introducing MonoDroid: Listing 1

MonoDroid Sample Application

using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;

namespace MonoDroidTestApplication
{
  [Activity(Label = "MonoDroid Test App", MainLauncher = true)]
  public class Activity1 : Activity
  {
    int count = 1;

    protected override void OnCreate(Bundle bundle)
    {
      base.OnCreate(bundle);

      // Set our view from the "main" layout resource
      SetContentView(Resource.layout.main);

      // Get our button from the layout resource,
      // and attach an event to it
      Button button = FindViewById<Button>(Resource.id.myButton);

      button.Click += delegate { button.Text = 
        string.Format("{0} clicks!", count++); };
    }
  }
}

About the Author

Wallace B. McClure is a Microsoft MVP, an ASPInsider and a partner in Scalable Development Inc. He's authored books on software architecture, ADO.NET and SQL Server, AJAX, and iPhone programming with Mono and MonoTouch. You can read McClure's blog at morewally.com.

Upcoming Events