Button Can't assign ID in layout XML

Former Member
Former Member
Lets say I have a very simple layout:

<layout id="MainLayout">

<button x="center" y="300" width="30" height="30" background="Gfx.COLOR_BLACK" behavior="kyle">
<state id="stateDefault" bitmap="@Drawables.LauncherIcon" />
</button>

</layout>

If I add an "id" field to the button element to make it:

<layout id="MainLayout">

<button id="mybutton" x="center" y="300" width="30" height="30" background="Gfx.COLOR_BLACK" behavior="kyle">
<state id="stateDefault" bitmap="@Drawables.LauncherIcon" />
</button>

</layout>

The app will crash on the setLayout() call with the error: "Could not find symbol mybutton"

I'd like to get reference to the button instance to hide or show it based on some condition. (is that possible.. Does a drawable have a 'visible' property? Hard to find that in the documentation)
  • The app will crash on the setLayout() call with the error: "Could not find symbol mybutton"

    This seems like a bug. If you generate the debug output for a simple button definition that has no id attribute, you'll see this...

    varrez_cmp_local_custom_selectable_F9WDUIQURYNIRLVSODWQ =
    newToybox.WatchUi.Button({
    :stateHighlighted => Gfx.COLOR_RED,
    :stateSelected => Gfx.COLOR_BLUE,
    :background => Gfx.COLOR_WHITE,
    :stateDefault => Gfx.COLOR_LT_GRAY,
    :stateDisabled => Gfx.COLOR_BLACK,
    :width => 50,
    :locX => 40,
    :locY => (dc.getHeight()/2)-(50/2),
    :height => 50
    });


    If you add an id attribute or a param element with the name set to identifier and the value "xxx", you get the following in the debug output.

    var rez_cmp_local_custom_selectable_xxx = newRez.Drawables.xxx();


    I'm not sure what purpose that serves, but it is not useful in this case. It almost seems as if they don't want you to be able to access the buttons by name. I think I'd file a bug report (post to the bug reports forum providing all of the necessary information.

    Does a drawable have a 'visible' property?

    No, the built-in Ui.Drawable does not have the concept of being visible/hidden.

    Travis
  • Former Member
    Former Member
    The app I was creating was having a start/stop feature, so I while the widget/app was 'Started', I wanted to update the button to say 'Stop'.

    However, maybe that does not fit the style guidelines - for that maybe I should be using the hardware start/stop button anyway- I just thought that users may have the feature running, and when pressing start/stop, if I capture the button and stop the system from the default action, it would be confusing... i.e., they actually wanted to end their ride.

    I guess if I go that route, needing to worry about a drawable button becomes a non issue.

    Thanks for your help,
    Kyle
  • I freely admit I don't use layouts so I can't help you there, but what you are considering can be done with dc calls. Here's an app I did for the Oregon 7xx. It has no "start" button, so I did it on the screen. Here I just do some simple draws, but you could use bitmaps. I know where I want the button, and put it there, with the text that is correct. Then in my delegate, I look for a tap where the button is and hanle it like a button press.