Hello World, Xamarin C# for Android
Pretty cool stuff to see C# code run natively on Android, using Xamarin and Mono. Not sure if I’ll be moving from Phonegap yet, but, it’s got great potential.
Here’s the Main Activity in C#:
using System;
using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;namespace XamarinHelloWorld
{
[Activity (Label = “Xamarin-HelloWorld”, MainLauncher = true, Icon = “@drawable/icon”)]
public class MainActivity : 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++);
};
}
}
}
And, I had to tweak the AndroidManifest.xml:
<?xml version=”1.0″ encoding=”utf-8″?>
<manifest xmlns:android=”http://schemas.android.com/apk/res/android” android:versionCode=”1″ android:versionName=”1.0″ package=”Xamarin_HelloWorld.Xamarin_HelloWorld”>
<uses-sdk android:targetSdkVersion=”19″ android:minSdkVersion=”19″ />
<application android:label=”Xamarin-HelloWorld”></application>
</manifest>
This was because I was using an API level 19 Emulator, and got this “minimum android version not supported by device” xamarin error whenever I tried to kick it off.