简体   繁体   中英

Click button on blackberry

How can I click a button field using the blackberry api? I'd like 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) .

这样使用EventInjector.NavigationEvent

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

            }
        });

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