I am new to BlackBerry development, having developed iPhone apps for years.
I am trying to do a simple menu like the following, invoked onLoad:
function initMenus() {
var item = new blackberry.开发者_高级运维ui.menu.MenuItem(false, 1, "Save", saveMe);
var item2 = new blackberry.ui.menu.MenuItem(false, 2, "Load", loadMe);
blackberry.ui.menu.addMenuItem(item);
blackberry.ui.menu.addMenuItem(item2);
}
function saveMe()
{
localStorage.pixels = window.pageYOffset;
}
function loadMe()
{
window.scrollTo(0, localStorage.pixels);
}
In the configuration file, I have:
<?xml version="1.0" encoding="utf-8"?>
<widget xmlns:rim="http://www.blackberry.com/ns/widgets" version="1.0.0" rim:header="RIM-Widget:rim/widget" xmlns="http://www.w3.org/ns/widgets">
<name>007</name>
<description>Sample Application created using the BlackBerry Widget SDK that demonstrates how to use the Menu and MenuItem objects found within the Widget API collection.</description>
<author href="http://na.blackberry.com/eng/developers/browserdev/widgetsdk.jsp" rim:copyright="2010" email="astanley@rim.com">Adam Stanley</author>
<content src="index.html" />
<feature id="blackberry.ui.menu" required="true" version="1.0.0.0" />
<rim:loadingScreen backgroundColor="#c0c0c0" />
<license href="" />
</widget>
Having installed the WebWorks last SDK, I can try with emulators of OS5 and OS6 families.
Now, with OS6 simulators everything is fine. JavaScript functions are properly called.
With OS5 simulators menu items are shown, but once I click on them, just nothing happens. I tried also with simple alerts, rather than to save and load data in localStorage, but functions are simply not called after clicking menu items.
What am I doing wrong?
I am aware that there is a known issue when declaring blackberry.ui.dialog
and blackberry.ui.menu
in the same application, but I'm just declaring blackberry.ui.menu
.
I noticed in both of the functions called, you're trying to access localStorage. On OS5, the regular HTML5 localStorage isn't supported, only Google Gears methods. Are you using the html5_init.js in your project? Follow these instructions to add it. It is a Google Gears to HTML5 "converter" for OS5.
That may not be your problem, but you'll need it anyway if you're writing a Webworks app that will work on both version of the OS.
精彩评论