Responding to User-Initiated Events
A user-initiated event is when a user interacts with a control in the application’s user interface, for example, when a user presses a button, types text in a text field, selects a check box, etc. You can add listeners to your model, so if a user-initiated event occurs for a control, your application can respond by taking an appropriate action.
Types of Listeners Mobile Development supports:
GainFocusListener listens for, when a user selects an object so that the user interface object gains focus.
LoseFocusListener listens for, when a user interface object loses focus because the user stops selecting an object when the user selects another user interface control.
PostEditListener listens for, when a user edits an object, for example an entry field, and generates an event after the object is edited.
PreEditListener listens for, when a user edits an object, for example an entry field, and generates an event when the user first selects the object for editing.
CompletedEditListener listens for, when a user edits an object, for example an entry field, and generates an event when the user ends the editing. End of editing means closing the keyboard or focusing another UI element.
TriggerListener listens for when, a user uses an object, for example, presses a button.
RowSelectionListener listens to trigger events for each row in a ListView object, for example, when a user selects one row. This listener can only be added as a child of a ContentProvider or ContentAdapter object.
SwipeListener listens to swipe events. You can define either a LeftToRight or RightToLeft swipe event. This listener can only be added to a normal View control (it is not possible to add it to a ListView, NavView or WebView control). You can only add one SwipeListener to a View control.
When you add the objects for event listeners to your application, Mobile Development generates the code to listen for the user-initiated events. You do not need to add custom logic to listen for the events.
How the application responds to a user-initiated event:
When you add listeners to your model, at run time if the listener detects the associated user-initiated event, the application fires an event. For example, if you add a TriggerListener object to a Button object, at run time when the user presses the button, the application fires an event. In addition to specifying listeners in the model, you can also define how the application responds to the event, in other words, the action the application takes when the event occurs.
Mobile Development provides these actions:
Back action to transition to the previous view.
ChangePaneConfiguration action to change the configuration of panes in the application's window.
Delegate action to execute a method that you code.
OpenDialog action to open an alert dialog that you have defined in your model.
ReloadContentProvider action to let a ContentProvider object reload its data source.
ToggleVisibility action to make a user interface object that you have defined in your model either visible or hidden. If the object is currently visible, the action hides the object. If the object is currently hidden, the action makes the object visible.
Transition action to transition to another view that you have defined in your model.
OpenSideView action to open a desired SideView.
CloseSideView action to close an already opened SideView.
To add event listeners and associated actions
2. In the Model section of the Outline Editor, right-click the user interface control for which you want to add a listener and select New Child > event_listener_object, where event_listener_object is one of the previously mentioned event listener, like TriggerListener.
3. Right-click the event listener object you added and select New Child > event_action_object, where event_action_object is one of the previously mentioned event action objects, e. g. OpenDialog. Please be aware, that every event listener supports any kind and number of actions. It is up to the developer to add the correct semantics to the project.
4. Select the event action object that you added.
Note:
Based on the event action you are using, you might also need to add application logic for the action.
Tip:
To update the Java classes that
Mobile Development generates for the project so that your changes are represented in the generated sources, save the project and regenerate sources. For instructions, see
Generating Sources for a Mobile Project.
Related Topics