当用户按菜单项时按下屏幕的正确方法是什么?我正在以这种方式开发我的代码,但我不知道它是否正确:
private MenuItem _descriptionItem = new MenuItem("Descripción",110, 10) {
public void run() {
int selectedIndex = _listField.getSelectedIndex();
final Event event = (Event)_listElements.elementAt(selectedIndex);
UiApplication.getUiApplication().invokeLater(new Runnable(){
public void run(){
Dialog.inform(event.getDescription());
}
});
}
};
谢谢!
答案 0 :(得分:1)
菜单项在事件线程上执行。所以你可以删除invokeLater代码。
private MenuItem _descriptionItem = new MenuItem("Descripción",110, 10) {
public void run() {
int selectedIndex = _listField.getSelectedIndex();
final Event event = (Event)_listElements.elementAt(selectedIndex);
Dialog.inform(event.getDescription());
}
};
答案 1 :(得分:0)
private MenuItem MNU_BACK = new MenuItem(null,100000000,100){ public void run(){ closeform(); }
public String toString() {
return "BACK";
}
};
答案 2 :(得分:0)
实际上已弃用:
private MenuItem _descriptionItem = new MenuItem("Descripción",110, 10)
{
public void run() {
int selectedIndex = _listField.getSelectedIndex();
final Event event = (Event)_listElements.elementAt(selectedIndex);
Dialog.inform(event.getDescription());
}
};
请改用:
private MenuItem _descriptionItem = new MenuItem(new StringProvider("Descripción"),110, 10)
{
public void run() {
int selectedIndex = _listField.getSelectedIndex();
final Event event = (Event)_listElements.elementAt(selectedIndex);
Dialog.inform(event.getDescription());
}
};
使用菜单项时,这将避免编译器警告。