Hi all.
I can't get past a problem with menu2 defined in XML: the ids of menu elements are apparently not assigned to menu entries. Since I have little experience with CIQ development, I might be doing something wrong.
I made a simple app which reproduces my problem out of a "widget" template and some sample code.
// app.mc
// This file was generated from "Widget" sample, except for row 21
using Toybox.Application;
class ciqtestmenu2App extends Application.AppBase {
function initialize() {
AppBase.initialize();
}
// onStart() is called on application start up
function onStart(state) {
}
// onStop() is called when your application is exiting
function onStop(state) {
}
// Return the initial view of your application here
function getInitialView() {
return [ new ciqtestmenu2View(), new ciqtestmenu2InitialDelegate() ]; //added a delegate here
}
}// initialDelegate.mc
using Toybox.System;
using Toybox.WatchUi;
class ciqtestmenu2InitialDelegate extends WatchUi.BehaviorDelegate
{
function initialize()
{
BehaviorDelegate.initialize();
}
function onMenu()
{
// Next line of code was taken from
// https://developer.garmin.com/connect-iq/programmers-guide/user-interface#builtinhandlers
// example for menu (not menu2, because there is no example of how to push XML-defined menu2 view)
WatchUi.pushView(new Rez.Menus.MainMenu(), new Menu2Delegate(), WatchUi.SLIDE_UP);
return true;
}
}// initialView.mc
// This file was generated from "Widget" sample
using Toybox.WatchUi;
class ciqtestmenu2View extends WatchUi.View {
function initialize() {
View.initialize();
}
// Load your resources here
function onLayout(dc) {
setLayout(Rez.Layouts.MainLayout(dc));
}
// Called when this View is brought to the foreground. Restore
// the state of this View and prepare it to be shown. This includes
// loading resources into memory.
function onShow() {
}
// Update the view
function onUpdate(dc) {
// Call the parent onUpdate function to redraw the layout
View.onUpdate(dc);
}
// Called when this View is removed from the screen. Save the
// state of this View here. This includes freeing resources from
// memory.
function onHide() {
}
}
// menu2Delegate.mc
// This code is from Class: Toybox::WatchUi::Menu2InputDelegate API reference
using Toybox.WatchUi;
using Toybox.System;
class Menu2Delegate extends WatchUi.Menu2InputDelegate {
function initialize() {
Menu2InputDelegate.initialize();
}
function onSelect(item) {
System.println(item.getId());
}
}
I've created a folder "menus" inside existing "resources" folder and added the following XML file menu.xml (sample code from https://developer.garmin.com/connect-iq/programmers-guide/user-interface#menu2xmlresources)
<menu2 id="MainMenu" title="@Strings.MainMenuTitle">
<menu-item id="generic1" label="Generic 1" subLabel="With Sublabel"></menu-item>
<menu-item id="generic2" label="Generic 2"></menu-item>
</menu2>
Added a string to existing ./resources/strings.xml:
<strings>
<string id="AppName">ciq-test-menu2</string>
<string id="MainMenuTitle">Settings</string>
</strings>
I get these warnings during build time:
BUILD: WARNING: Rez:37: Unable to detect scope 'MenuItem' for the symbol 'initialize'. BUILD: WARNING: Rez:38: Unable to detect scope 'MenuItem' for the symbol 'initialize'.
and the following console output after selecting (and pressing for confirmation) both menu2 entries in simulator:
symbol (21) symbol (22)
The result I'm expecting should be something like "generic1" and "generic2" given the ids.
I'm using connectiq-sdk-lin-3.1.6-2019-10-23-2de4665c6 with Eclipse.