Skip to content

Instantly share code, notes, and snippets.

@mattleibow
Created February 26, 2015 13:25
Show Gist options
  • Save mattleibow/32e0a9fcc4a59893c25b to your computer and use it in GitHub Desktop.
Save mattleibow/32e0a9fcc4a59893c25b to your computer and use it in GitHub Desktop.
Disposing Dialogs
// in normal code flow:
[Activity(Label = "App1", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
var button = FindViewById<Button>(Resource.Id.MyButton);
button.Click += delegate
{
using (var dialog = new ColorPickerDialog(this))
dialog.Show();
};
}
}
// my dialog
public class ColorPickerDialog : Dialog
{
public ColorPickerDialog(Context context)
: base(context)
{
RequestWindowFeature((int)WindowFeatures.NoTitle);
}
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
var okButton = new Button(this.Context);
okButton.Text = "hi";
SetContentView(okButton);
okButton.Click += delegate
{
Dismiss();
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment