Reputation: 5830
What is the correct way in order to push an screen when the user press a Menu Item? I'm developing my code in this way but i don't know if it is the right:
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());
}
});
}
};
Thanks!
Upvotes: 0
Views: 154
Reputation: 361
This is actually deprecated:
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());
}
};
Use this instead:
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());
}
};
This will avoid compiler warnings when using Menu Item.
Upvotes: 0
Reputation: 921
private MenuItem MNU_BACK = new MenuItem(null, 100000000, 100) { public void run() { closeform(); }
public String toString() {
return "BACK";
}
};
Upvotes: 0
Reputation: 15303
menu items are executed on the event thread. So you can remove invokeLater code.
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());
}
};
Upvotes: 1