简体   繁体   中英

Blackberry button click handler

I want to run some Java code when the user clicks on this ToolbarButtonField in my BlackBerry app. I have the following code which is not working. Please tell me where I am wrong.

butHome = new ToolbarButtonField(new StringProvider("Home"));
butHome.setChangeListener(new FieldChangeListener() {
    public void fieldChanged(Field field, int context) {
        System.out.println("Clicked...");
    }
});

Try this:

butHome = new ToolbarButtonField(new StringProvider("Home")) {
    protected boolean navigationClick(int status, int time) {
        System.out.println("Clicked...");
        return true;
    }
});

You can use:

ToolbarButtonField#invoke

Performs an action when this ToolbarButtonField is clicked on if Command has been set. A click is defined as the following sequence of touch events: TouchEvent.DOWN, TouchEvent.CLICK, TouchEvent.UNCLICK and TouchEvent.UP.

You're going to have to use that in conjuction with the Command framework . If that's not desirable, override ToolbarButtonField#touchEvent for a TouchEvent.UNCLICK event to execute the desired code.

public boolean touchEvent(TouchEvent message) {
  if ( message.geEvent() == TouchEvent.UNCLICK ) {
         // do what I want.
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM