Note that there are some explanatory texts on larger screens.

plurals
  1. POinvoking native MenuItem(Switch Application, Close, etc.) in my CustomMenu in blackberry
    primarykey
    data
    text
    <p>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 <code>PopupScreen</code> and having my <code>MenuItem</code> as a customized <code>LabelField</code> with abstract <code>invokeAction()</code> method. I made the <code>invokeAction()</code> method as abstract to emulate the run() method of <code>MenuItem</code>. </p> <p><img src="https://i.stack.imgur.com/tLRv7.png" alt="enter image description here"></p> <p>Everything was ok but I remember something. What if my boss ask me to implement native <code>MenuItem</code>s like <strong>Switch Application</strong> and <strong>Close</strong>. I don't think implementing <strong>Close</strong> will be a problem, but the <strong>Switch Application</strong> and other native <code>MenuItem</code> like <strong>Show Keyboard</strong>, this will give me a problem. So I come up for another solution and this is my code: </p> <pre><code>public CustomMenu(MainScreen screen) { super(vfm); Menu menu = screen.getMenu(0); for(int i = 0; i &lt; 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; } }); } } </code></pre> <p>This is the constructor of my <code>CustomMenu</code>. I accept an instance of <code>MainScreen</code> as my parameter to get the the lists of <code>MenuItem</code> and add it to my existing <code>CustomMenu</code>. The <code>invokeAction()</code> overridden method there is the counterpart of <code>run()</code> method of <code>MenuItem</code>. And this is the result of what I did: </p> <p><img src="https://i.stack.imgur.com/yilu0.png" alt="enter image description here"></p> <p>I managed to put those native <code>MenuItem</code> in my <code>CustomMenu</code> but the problem is when I invoke(click) those native <code>MenuItem</code>(Switch Application, Close) I got an <code>IllegalStateException</code>. Is there a way to get the implementation of those native <code>MenuItem</code>? Or a way to capture the <code>run()</code> method of <code>MenuItem</code> then invoke it in my <code>CustomMenu</code>? </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload