Dynamic Menu identifiers: converting Strings to Symbols?

Hi,

My app uses an ActionMenu to let the user select a value from a list. On Edge devices, ActionMenu isn’t available, so I’d like to fall back to a Menu instead.

The problem is that Menu items use a Symbol as the item identifier. My list is built dynamically from an array of String labels and String identifiers.

Is there a way to convert a String to a Symbol? If not, is there another recommended approach to use a variable list of strings as identifiers in a Menu? Or is Menu2 the better option here?

Regards, Robert

Top Replies

  • Is there a way to convert a String to a Symbol?

    No. Symbols are integers under the covers, and new symbols are uniquely assigned to ints at compile time. You can't map arbitrary / dynamic…

All Replies

  • Is there a way to convert a String to a Symbol?

    No. Symbols are integers under the covers, and new symbols are uniquely assigned to ints at compile time. You can't map arbitrary / dynamic data to a symbol at run time.

    (Note that the SDK has information mapping existing API symbols to ints, so that your code works when it references existing symbols that are present in the device firmware / SDK code.)

    a Menu? Or is Menu2 the better option here?

    Menu2 is always the better option than Menu, except for the oldest devices where Menu is not available at all. (But in that case, a 3rd party / DIY view might be better for some purposes.)

    - Menu has a bug in certain old devices like FR935 where the menu title is incorrectly displayed as "English", and it won't be fixed now

    - Menu has less functionality than Menu2

    - Menu2 is some sort of wrapper around the built-in native menu of your device, so that your Menu2 views will have the same look and feel as native menus. Menu may or may not have the same property (at least on CIQ1 devices, Menu is extremely barebones and doesn't look anything like the native menus).

    Indeed, the CIQ dev doc page which shows you how to create menus in XML only references <menu2> (which creates a Menu2), and not the old <menu> tag (which creates a Menu):

    https://developer.garmin.com/connect-iq/core-topics/resources/

    Standard Menus

    Menus are defined using the <menu2> element

    Garmin would probably prefer that we all forget that Menu ever existed. I don't see a reason to use Menu except on super old CIQ1 devices where Menu2 is unavailable. But again, Menu sucks so bad on those devices that I would probably use a 3rd party menu, like:

    https://github.com/flowstatedev/Dmenu 

  • Understood, thanks! I initially thought that Menu might be the easier option when the user only needs to choose from a list of options. However, after thinking it through, this can be done just as easily with Menu2, so I’ll go with that.

  • In Menu2 (which uses the confusing MenuItem and not MenuItem2) the identifier is Object, not symbol, so you can use the string directly.

  • In Menu2 (which uses the confusing MenuItem and not MenuItem2) the identifier is Object, not symbol, so you can use the string directly.

    While this is good context for others reading the thread, I think OP understood that:

    Is there a way to convert a String to a Symbol? If not, is there another recommended approach to use a variable list of strings as identifiers in a Menu? Or is Menu2 the better option here?
  • You could just let them respond instead of speculating why asking how to convert string to symbol means that he understands that Menu2 can be used with string (in which case he probably shouldn't ask the question, just use Menu2 with the string)

  • Thanks, yes, I have already been using Menu2, or more precisely CustomMenu, quite extensively.

    For this particular use case, I now tried Menu2 first, but in the end went with a CustomMenu implementation to keep it visually consistent with the rest of my app. This required a bit more coding effort overall, but now it both works well and looks good.