Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
MonoDroid 'hello world' examples (simple, layout-less sample app)
using Android.App;
using Android.OS;
using Android.Widget;
namespace Demo
{
[Activity(Label = "HelloWorld", MainLauncher = true)]
public class HelloWorldActivity : Activity
{
int count = 0;
Button b;
//TextView tv;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
b = new Button(this);
b.SetText("Click me", TextView.BufferType.Normal);
b.Click += delegate { b.Text = string.Format("{0} clicks!", ++count); };
SetContentView(b); // example #1
#region Example 2
//tv = new TextView(this);
//tv.SetText("Welcome to MonoDroid...", Android.Widget.TextView.BufferType.Normal);
//LinearLayout ll = new LinearLayout(this);
//ll.Orientation = Orientation.Vertical;
//ll.AddView(tv);
//ll.AddView(b);
//SetContentView(ll); // example #2
#endregion
#region Example 3
//RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(200, 50);
//b.LayoutParameters = rlp;
//tv.LayoutParameters = rlp;
//RelativeLayout rl = new RelativeLayout(this);
//rl.AddView(tv);
//rl.AddView(b);
//SetContentView(rl); // example #3
#endregion
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment