I'm struggling to dynamically add a WatchUi.Button object, in particular getting it to display an image from the resources, and also getting it to call the behavior handler.
As a test I've used the example from the "Selectable" project and implement a layout, and I can get the image/behavior to work with something like this...
<button x="100" y="100" width="100" height="100"> <state id="stateDefault" bitmap="@Drawables.ButtonImage" /> <state id="stateHighlighted" bitmap="@Drawables.ButtonClickImage" /> <param name="background">@Drawables.ButtonImage</param> <param name="behavior">onBtnClick</param> </button>
However, if I try and do the same thing in the onDraw of my view, I'm just not getting anything...
var btnImage = WatchUi.loadResource(Rez.Drawables.ButtonImage); var btnClickImage = WatchUi.loadResource(Rez.Drawables.ButtonClickImage); var btn = new WatchUi.Button({:locX=>100,:locY=>100,:width=>100,:height=>100,:background=>btnImage,:stateDefault=>btnImage,:stateHighlighted=>btnClickImage,:behavior=>:onBtnClick}); btn.draw(dc);
And in my delegate I have...
function onBtnClick() { System.println("Button clicked"); }
Firstly the images simply aren't appearing, and second the event handler isn't being called... why? (I'm assuming it's my lack of understanding/knowledge around drawables and symbols.)
I've also tried setting the background, stateDefault and stateHighlighted to Graphics.COLOR_XXX (with different ones for the different states)... this shows the "background" colour, but it never changes to the "stateDefault" or "stateHighlighted"