BlackBerry OS 6 本机菜单
您好,我正在尝试为我的本机菜单创建一个全局类,但似乎可以将其加载到我的屏幕类中,我希望它显示在我想要显示的任何位置。
不确定我做得是否正确
这是我的 MenuItems 类
public final class MenuItems extends MainScreen {
public void getMenuItems(){
MenuItem myItem = new MenuItem(new StringProvider("My Cards"), 0x230000, 0);
myItem.setCommandContext(new Object(){
public String toString(){
return "My Cards";
}
});
myItem.setCommand(new Command(new CommandHandler(){
public void execute(ReadOnlyCommandMetadata metadata, Object context){
// Do Something
}
}));
addMenuItem(myItem);
}
}
我想要将其添加到的 Screen 类是这个,不确定我是否会在这里调用它,我尝试创建一个新实例并只获取 get 方法,但没有幸运的是,但是如果我将上面的类中的代码转储到这个类中,它会正常工作,但我不希望这样。
public final class MobiScreen extends MainScreen {
ToolBar toolbar = new ToolBar();
Banner banner = new Banner("Welcome");
MenuItems myMenu = new MenuItems();
public MobiScreen()
{
setTitle(toolbar.getToolBar());
setBanner(banner.getBanner());
myMenu.getMenuItems();
}
}
Hi I am trying to create a global class for my Native Menu, but can seem to get it to load in my Screen Class, I want this to show up where ever I would like to show up.
Not sure if I am doing it right
Here is my MenuItems Class
public final class MenuItems extends MainScreen {
public void getMenuItems(){
MenuItem myItem = new MenuItem(new StringProvider("My Cards"), 0x230000, 0);
myItem.setCommandContext(new Object(){
public String toString(){
return "My Cards";
}
});
myItem.setCommand(new Command(new CommandHandler(){
public void execute(ReadOnlyCommandMetadata metadata, Object context){
// Do Something
}
}));
addMenuItem(myItem);
}
}
The Screen Class I want to add it to is this, not sure if how I would call it here, I tried creating a new instance and just fetching the get method, but no luck, but if I dump the code from the above class in to this class, it will work fine, but I don't want that.
public final class MobiScreen extends MainScreen {
ToolBar toolbar = new ToolBar();
Banner banner = new Banner("Welcome");
MenuItems myMenu = new MenuItems();
public MobiScreen()
{
setTitle(toolbar.getToolBar());
setBanner(banner.getBanner());
myMenu.getMenuItems();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不让 MobiScreen 扩展您的 MenuItems 类?
public class MobiScreen extends MenuItems { ... }
Why not have MobiScreen extend your MenuItems class?
public class MobiScreen extends MenuItems { ... }