Skip to content

Instantly share code, notes, and snippets.

@phanngoc
Created November 3, 2015 12:42
Show Gist options
  • Select an option

  • Save phanngoc/927385bb762bbfce2cde to your computer and use it in GitHub Desktop.

Select an option

Save phanngoc/927385bb762bbfce2cde 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;
namespace bom1
{
[Activity (Label = "bom1", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
int count = 1;
DateTime _date;
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++);
ShowDialog (0);
};
_date = DateTime.Today;
button.Text = _date.ToString ("d");
var editText = FindViewById<EditText> (Resource.Id.editText);
var textView = FindViewById<TextView> (Resource.Id.textView);
editText.TextChanged += (object sender, Android.Text.TextChangedEventArgs e) => {
textView.Text = e.Text.ToString ();
};
}
protected override Dialog OnCreateDialog (int id)
{
return new DatePickerDialog (this, HandleDateSet, _date.Year,
_date.Month - 1, _date.Day);
}
void HandleDateSet (object sender, DatePickerDialog.DateSetEventArgs e)
{
_date = e.Date;
var button = FindViewById<Button> (Resource.Id.myButton);
button.Text = _date.ToString ("d");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment