Created
February 26, 2015 13:25
-
-
Save mattleibow/32e0a9fcc4a59893c25b to your computer and use it in GitHub Desktop.
Disposing Dialogs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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