I need to create a custom menu in my blackberry application so that I can manage its appearance. I managed to create my custom menu by creating a class which extends a PopupScreen
and having my MenuItem
as a customized LabelField
with abstract invokeAction()
method. I made the invokeAction()
method as abstract to emulate the run() method of MenuItem
.
Everything was ok but I remember something. What if my boss ask me to implement native MenuItem
s like Switch Application and Close. I don't think implementing Close will be a problem, but the Switch Application and other native MenuItem
like Show Keyboard, this will give me a problem. So I come up for another solution and this is my code:
public CustomMenu(MainScreen screen) {
super(vfm);
Menu menu = screen.getMenu(0);
for(int i = 0; i < menu.getSize(); i++){
final MenuItem finalMenu = menu.getItem(i);
vfm.add(new CustomMenuItem(finalMenu.toString(), Field.FOCUSABLE){
protected boolean invokeAction(int action) {
finalMenu.run();
return true;
}
});
}
}
This is the constructor of my CustomMenu
. I accept an instance of MainScreen
as my parameter to get the the lists of MenuItem
and add it to my existing CustomMenu
. The invokeAction()
overridden method there is the counterpart of run()
method of MenuItem
. And this is the result of what I did:
I managed to put those native MenuItem
in my CustomMenu
but the problem is when I invoke(click) those native MenuItem
(Switch Application, Close) I got an IllegalStateException
. Is there a way to get the implementation of those native MenuItem
? Or a way to capture the run()
method of MenuItem
then invoke it in my CustomMenu
?