开发者

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...");
    }
});


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.
  }
}


Try this:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜