From de19befe092bf445e3223d5683688c2f536b64e7 Mon Sep 17 00:00:00 2001 From: Rui Marinho Date: Thu, 8 May 2014 23:09:04 +0100 Subject: [PATCH] Adding Selection Change to RadioGroup This would make it easier to access the value when it changes for any grouped item. --- MonoTouch.Dialog/Elements.cs | 13 +++++++++++-- Sample/DemoElementApi.cs | 23 +++++++++++++++-------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/MonoTouch.Dialog/Elements.cs b/MonoTouch.Dialog/Elements.cs index 30aeb601..58f46a82 100644 --- a/MonoTouch.Dialog/Elements.cs +++ b/MonoTouch.Dialog/Elements.cs @@ -2459,12 +2459,21 @@ public Group (string key) /// Captures the information about mutually exclusive elements in a RootElement /// public class RadioGroup : Group { + + public Action SelectionChanged { get; set;} int selected; public virtual int Selected { get { return selected; } - set { selected = value; } + set { + if (value != selected) { + selected = value; + if (SelectionChanged != null) + SelectionChanged (selected); + } + + } } - + public RadioGroup (string key, int selected) : base (key) { this.selected = selected; diff --git a/Sample/DemoElementApi.cs b/Sample/DemoElementApi.cs index 127b3ebb..385ded77 100644 --- a/Sample/DemoElementApi.cs +++ b/Sample/DemoElementApi.cs @@ -84,27 +84,34 @@ RootElement CreateRoot () RootElement CreateSoundSection () { - return new RootElement ("Sounds"){ + return new RootElement ("Sounds") { new Section ("Silent") { new BooleanElement ("Vibrate", true), }, new Section ("Ring") { new BooleanElement ("Vibrate", true), new FloatElement (null, null, 0.8f), - new RootElement ("Ringtone", new RadioGroup (0)){ - new Section ("Custom"){ + new RootElement ("Ringtone", new RadioGroup (0) { + SelectionChanged = + new Action ((int obj) => { + using (var msg = new UIAlertView ("RadioGroup",string.Format("you selected : {0}", obj), null, "Ok")){ + msg.Show (); + } + }) + }) { + new Section ("Custom") { new RadioElement ("Circus Music"), new RadioElement ("True Blood"), }, - new Section ("Standard"){ + new Section ("Standard") { from n in "Marimba,Alarm,Ascending,Bark,Xylophone".Split (',') - select (Element) new RadioElement (n) + select (Element)new RadioElement (n) } }, - new RootElement ("New Text Message", new RadioGroup (3)){ - new Section (){ + new RootElement ("New Text Message", new RadioGroup (3)) { + new Section () { from n in "None,Tri-tone,Chime,Glass,Horn,Bell,Eletronic".Split (',') - select (Element) new RadioElement (n) + select (Element)new RadioElement (n) } }, new BooleanElement ("New Voice Mail", false),