Tobio
Tobio

Reputation: 255

Connect Blackberry menuitem to onscreen buttons

I have requirement for having onscreen navigation buttons along with menu items on blackberry. I need to generate menu item commands as onscreen buttons. Is there a way to generate onscreen menu item buttons in Blackberry? i.e On each screen of my application the menu items should be populated as onscreen buttons both having same functionality?

Thank you

Upvotes: 0

Views: 214

Answers (1)

Core.B
Core.B

Reputation: 662

The easiest way to accomplish what you're trying to do is write one function then have both the button and the menu item use the same function.

For example:

function doSomething() {
   // Your Code Here
}

// In the function building your screen
MenuItem somethingMi = new MenuItem() {
  private MenuItem() { super("Do Something",100001, 5); }

  public void run() { doSomething() };
}

Button somethingBtn = new ButtonField("Do Something");
somethingBtn.setChangeListener(new FieldChangeListener() {
  public void fieldChanged(Field field, int context){
    doSomething();
  }
}

addMenuItem(somethingMI);
add(somethingBtn);

Upvotes: 1

Related Questions