开发者

Click button on blackberry

开发者 https://www.devze.com 2023-02-24 19:53 出处:网络
How can I click a button field using the blackberry api? I\'d li开发者_如何转开发ke to mimic pressing a button as if the user pressed it.Suppose you have this code (taken from the BB API doc):

How can I click a button field using the blackberry api? I'd li开发者_如何转开发ke to mimic pressing a button as if the user pressed it.


Suppose you have this code (taken from the BB API doc):

FieldChangeListener listener = new FieldChangeListener() {
    public void fieldChanged(Field field, int context) {
        ButtonField buttonField = (ButtonField) field;
        System.out.println("Button pressed: " + buttonField.getLabel());
    }
};
ButtonField buttonField = new ButtonField("Test Button");
buttonField.setChangeListener(listener);

Then you can programmatically simulate a click by calling the fieldChangeNotify(int context) method of the buttonField. Note that you can distinguish normal/real click from a programmatic one by checking the context in the fieldChanged(Field field, int context). It is the same context you pass in fieldChangeNotify(int context).


Use EventInjector.NavigationEvent like this:

EventInjector.invokeEvent(new EventInjector.NavigationEvent(EventInjector.Navig ationEvent.NAVIGATION_CLICK, 0, 0, 0));


 ButtonField buttonField = new ButtonField("Test Button" ,ButtonField.CONSUME_CLICK);
          buttonField.setChangeListener(new FieldChangeListener() 
          {
            public void fieldChanged(Field field, int context) 
            {
                Dialog.alert("Test Button Clicked");

            }
        });
0

精彩评论

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