0

I am developing a Unit Converter using Monotouch.Dialog, and I have a main window that looks like this:

Unit converter main window

When I tap the Quantity element, select a new Quantity and return to the main window, I want to update the Unit elements with a table of units associated with the selected quantity.

My initial thought was to make an update of the units in an event handler that would be invoked after completed quantity selection. However, I have not been able to find an event in the MT.D API that is fired when I return from the quantity selection. Is there such an event that I could act upon, or is there another way I can do the unit updating?

Schematically, my AppDelegate.FinishedLaunching method looks like this right now:

public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
  _window = new UIWindow (UIScreen.MainScreen.Bounds);

  _quantityGroup = new RadioGroup("Qty", 0);
  _fromUnitGroup = new RadioGroup("FromU", 0);
  _toUnitGroup = new RadioGroup("ToU", 0);

  var quantityElem = new RootElement("Quantity", _quantityGroup) { 
      new Section() { new RadioElement("AbsorbedDose", "Qty") as Element, ... }};

  var fromUnitElem = new RootElement("Unit", _fromUnitGroup) { new Section() };
  var toUnitElem = new RootElement("Unit", _toUnitGroup) { new Section() }

  _rootElement = new RootElement ("Unit Converter")
  {
    new Section() { quantityElem }, 
    new Section("From") { new EntryElement(...), fromUnitElem },
    new Section("To") { new EntryElement(...), toUnitElem }
  };

  _rootVC = new DialogViewController(_rootElement);
  _nav = new UINavigationController(_rootVC);

  _window.RootViewController = _nav;
  _window.MakeKeyAndVisible();

  return true;
}
Anders Gustafsson
  • 15,837
  • 8
  • 56
  • 114
  • 1
    see this question - http://stackoverflow.com/questions/8302306/monotouch-dialog-responding-to-a-radiogroup-choice. I have a more complete example somewhere if you need it. – Jason May 29 '12 at 19:57
  • Great, many thanks for your help, Jason! I searched for an SO answer before posting my question, but I did not see that one. As also pointed out in the comments in that answer, this would be a great addition to MT.D. – Anders Gustafsson May 30 '12 at 05:18

1 Answers1

2

As pointed out by Jason in a comment above this problem had been addressed previously on SO, here.

The solution is to extend the RadioElement class, where the inheriting class contains an OnSelected event and the RadioElement.Selected method is overridden with a method that invokes the OnSelected event handler(s).

Community
  • 1
  • 1
Anders Gustafsson
  • 15,837
  • 8
  • 56
  • 114
  • Does anyone else think that there should be a better way do do this? I don't know one right now... but, I'm continuing my search – BRogers Mar 01 '13 at 19:53