MonoTouch.Dialog: response to RadioGroup choice

I have a dialog created by MonoTouch.Dialog. The radio group has a list of Doctors:

Section secDr = new Section ("Dr. Details") { new RootElement ("Name", rdoDrNames){ secDrNames } 

I want to update the Element code in the code after Doctor is selected. What is the best way to get notified when choosing RadioElement ?

+8
c # ios radio-button monotouch.dialog
source share
1 answer

Create your own RadioElement as:

 class MyRadioElement : RadioElement { public MyRadioElement (string s) : base (s) {} public override void Selected (DialogViewController dvc, UITableView tableView, NSIndexPath path) { base.Selected (dvc, tableView, path); var selected = OnSelected; if (selected != null) selected (this, EventArgs.Empty); } static public event EventHandler<EventArgs> OnSelected; } 

Note: do not use a static event if you want to have more than one radio group

Then create RootElement that use this new type, for example:

  RootElement CreateRoot () { StringElement se = new StringElement (String.Empty); MyRadioElement.OnSelected += delegate(object sender, EventArgs e) { se.Caption = (sender as MyRadioElement).Caption; var root = se.GetImmediateRootElement (); root.Reload (se, UITableViewRowAnimation.Fade); }; return new RootElement (String.Empty, new RadioGroup (0)) { new Section ("Dr. Who ?") { new MyRadioElement ("Dr. House"), new MyRadioElement ("Dr. Zhivago"), new MyRadioElement ("Dr. Moreau") }, new Section ("Winner") { se } }; } 

[UPDATE]

Here is a more modern version of this RadioElement:

 public class DebugRadioElement : RadioElement { Action<DebugRadioElement, EventArgs> onCLick; public DebugRadioElement (string s, Action<DebugRadioElement, EventArgs> onCLick) : base (s) { this.onCLick = onCLick; } public override void Selected (DialogViewController dvc, UITableView tableView, NSIndexPath path) { base.Selected (dvc, tableView, path); var selected = onCLick; if (selected != null) selected (this, EventArgs.Empty); } } 
+18
source share

All Articles