PDA

View Full Version : What is the best way to get clicked menuItem in menu?



fangzhouxing
28 May 2009, 6:18 PM
My current code :


Menu mainMenu = new Menu();
mainMenu.add(new MenuItem("menu 1"));
mainMenu.add(new MenuItem("menu 2"));
mainMenu.add(new MenuItem("menu 3"));

Listener<MenuEvent> itemListener = new Listener<MenuEvent>() {
public void handleEvent(MenuEvent be) {
El el = be.getTargetEl();
String text = el.getInnerHtml();
if (text.indexOf("menu 1")>0) {
Log.info(" menu 1 selected");
}
}
};
mainMenu.addListener(Events.OnClick, itemListener);



Any advice? Thanks in advance.

sven
29 May 2009, 12:47 AM
The menuItems fire a Select event. You should listen to that