Skip to content

Instantly share code, notes, and snippets.

@flockonus
Created December 29, 2012 06:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flockonus/4405026 to your computer and use it in GitHub Desktop.
Save flockonus/4405026 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;
using System.Threading;
namespace HelloAndroid
{
[Activity (Label = "HelloAndroid", MainLauncher = true)]
public class Activity1 : Activity
{
int count;
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
SwitchLayoutA();
//base.OnCreate (bundle);
}
protected void SwitchLayoutA ()
{
//Create the user interface in code
var layout = new LinearLayout (this);
layout.Orientation = Orientation.Vertical;
var aLabel = new TextView (this);
aLabel.SetText(Resource.String.helloLabelText);
var aButton = new Button (this);
aButton.SetText(Resource.String.helloButtonText);
aButton.Click += (sender, e) => {
aLabel.Text = "Hello from the button";
SwitchLayoutB ();
};
layout.AddView (aLabel);
layout.AddView (aButton);
SetContentView (layout);
}
protected void SwitchLayoutB ()
{
// Set our view from the "main" layout resource
SetContentView (Resource.Layout.Main);
count = 1;
Button button = FindViewById<Button> (Resource.Id.myButton);
button.Click += delegate {
if( count > 3 ){
System.Threading.Tasks.Task.Factory.StartNew (() => {
Thread.Sleep(3000);
// !! APLICATION STOP RESPONDING. No error log shows in console.
SwitchLayoutA();
});
return;
}
button.Text = string.Format ("{0} clicks!", count++);
};
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment