I am using the Menu2 item to programatically create a menu. However I am having issues picking up which item has been selected.
Here is my code to create the menu:
class velo_view_top_menu extends Ui.Menu2
{
function initialize()
{
Ui.Menu2.initialize({:title=>"Main Menu"});
// Add a new MenuItem to the Menu2 object
addItem(
new Ui.MenuItem(
"Connection",
"Device connections",
"item_1",
{}
)
);
addItem(
new Ui.MenuItem(
"Settings",
"Device settings",
"item_2",
{}
)
);
}
}
And here is my code in the delegate:
class velo_view_top_menu_delegate extends Ui.Menu2InputDelegate {
function initialize() {
Menu2InputDelegate.initialize();
}
function onSelect(item) {
switch (item.getId())
{
case :item_1:
System.println("A");
WatchUi.pushView(new velo_view_connection_menu(), new velo_view_connection_menu_delegate(), Ui.SLIDE_LEFT);
break;
case :item_2:
System.println("B");
WatchUi.pushView(new velo_view_setting_menu(), new velo_view_setting_menu_delegate(), Ui.SLIDE_LEFT);
}
if (item.getId() == :item_1)
{
System.println("C");
}
if (item.getId() == "item_1")
{
System.println("D");
}
System.println("E");
System.println(item.getId());
}
}
When I select the first item, this is the output I get:
E
item_1
So neither the select, if statement with symbol, or if statement with string work. What am I doing wrong?