OdeToCode IC Logo

MonoDroid Preview

Tuesday, January 11, 2011

MonoDroid allows you to write Android applications using C# and Visual Studio.

Compare the code in the last post to the following:

[Activity(Label = "My Activity", MainLauncher = true)]
public class Activity1 : Activity
    protected override void OnCreate(Bundle bundle)

        Button button = FindViewById<Button>(Resource.id.button);
        TextView view = FindViewById<TextView>(Resource.id.text);

        button.Click += (s, args) => view.Text = "Clicked!";
        button.LongClick += (s, args) =>
                                    view.Text = "Long click!";
                                    args.ReturnValue = false;

MonoDroid looks promising. It does all the hard work of mapping Android APIs and idioms into a proper C# representation (notice how the long click Java listener in the last post returns a value, while the long click C# event handler in this post sets a flag in the event arguments). It's little touches like these that make a difference.

MonoDroid also includes a Visual Studio plugin to deploy and debug on the Android simulator, or a real device (even over Wifi). That's a lot of great magic behind the F5 button.