Hi
I'm developing a WatchApp and I'm having trouble with adding a WatchUI button. When I press the button, nothing happens. I've tried various solutions, but none have worked. I'm not sure if the issue lies in the delegate or elsewhere. As I'm new to app development, I would appreciate any help or guidance on what might be going wrong. My first attemp is when i clicked put the lactato value to -1.
This is my codes:
<layout id="MainLayout"> <bitmap id="type_tittle" filename="../drawables/blod_64.png" x="center" y="20%" /> <label id="text_sweat" text="Lactate in sweat" x="center" y="50%" font="Gfx.FONT_MEDIUM" justification="Gfx.TEXT_JUSTIFY_CENTER" /> <label id="lactato_value" text="0 mmol/L" x="center" y="70%" font="Gfx.FONT_MEDIUM" justification="Gfx.TEXT_JUSTIFY_CENTER" /> <button x="100" y="300" width="50" height="21"> <state id="stateDefault" bitmap="@Drawables.next_button" /> <param name="background">Gfx.COLOR_RED</param> </button> </layout>
Y este mi view
import Toybox.Graphics; import Toybox.WatchUi; import Toybox.Lang; import Toybox.Timer; class Lesson2View extends WatchUi.View { private var _lactato_value; private var arrayValues = [1.9, 2.0, 3.9, 4.0, 4.1] as Array<Float>; private var currentIndex = 0; private var myTimer = new Timer.Timer(); private var nextButton; function initialize() { View.initialize(); } function timerCallback() { if (currentIndex < arrayValues.size()) { setLactatoValue(arrayValues[currentIndex]); currentIndex++; } else { setLactatoValue(-1.0); myTimer.stop(); } WatchUi.requestUpdate(); } function onLayout(dc as Graphics.Dc) as Void { View.onLayout(dc); setLayout(Rez.Layouts.MainLayout(dc)); // Load layout _lactato_value = findDrawableById("lactato_value"); // Add button to the view setLactatoValue(2.3); // Start timer myTimer.start(method(:timerCallback), 1000, true); } function onShow() as Void { } function onUpdate(dc as Graphics.Dc) as Void { View.onUpdate(dc); } function onHide() as Void { } function setLactatoValue(lactato as Float) as Void { var label, color; color = Graphics.COLOR_WHITE; label = lactato.format("%.2f") + " mmol/L"; // Formatear el número a dos decimales switch (true) { case lactato < 2.0 && lactato >= 0.0: color = Graphics.COLOR_DK_GREEN; break; case lactato < 4.0 && lactato >= 2.0: color = 0xFFA500; break; case lactato >= 4.0: color = Graphics.COLOR_RED; break; case lactato < 0.0: color = Graphics.COLOR_WHITE; } if (lactato < 0.0) { _lactato_value.setText("No data"); _lactato_value.setColor(color); } else if (_lactato_value != null) { _lactato_value.setText(label); _lactato_value.setColor(color); WatchUi.requestUpdate(); } } }
And my delegate is the same when i create the project
import Toybox.Lang; import Toybox.WatchUi; class Lesson2Delegate extends WatchUi.BehaviorDelegate { var view; function initialize() { BehaviorDelegate.initialize(); } function onView(v as WatchUi.View) { view = v; } function onButtonPress() { // Acción que se realizará al presionar el botón System.println("Button pressed!"); view.setLactatoValue(-1.0); // Puedes personalizar esta acción según tus necesidades } }
Thanks for your time.