Installing and using Mobile Suite : webMethods Mobile Designer Native User Interface Reference : Mobile Designer Native User Interface : Handling Events Generated by User Actions
Handling Events Generated by User Actions
When a user interacts with the application, for example, pressing a button in the user interface, events can be generated.
About Listeners
You should set up the application so that it listens for events and takes appropriate measures to handle events. To listen for events, set up the application to implement the nUIEventListener class and register the classes as event listeners. As a result, the application receives events related to the currently active NativeUI object.
You can define listeners for individual NativeUI objects so that an object can have its own listener or an alternate listener. To do so, add the listener directly to the object using nUIObject.addEventListener().
Types of Events
The types of events for which an application can listen are defined in the nUIConstants class. For more information, see webMethods Mobile Designer Java API Reference.
An application can listen for:
*Events that the NativeUI system generates
When a user interacts with a NativeUI object in an application’s user interface, the NativeUI system generates an event. For example, an EVT_GAIN_FOCUS event is generated when an object gains focus. The events that the NativeUI system can generate are defined by com.softwareag.mobile.runtime.nui.nUIConstants.
*HTTP events
The HTTP events are EVT_TRIGGER_HTTP_SUCCESS and EVT_TRIGGER_HTTP_FAIL. These events are not related to any specific Mobile Designer classes. The HTTP events are available if the application requires this functionality.
*Custom-defined events
You can define custom events. CUSTOM_EVENT_CODE0 is the first constant value that is not reserved for use within the NativeUI system. When defining custom events, you can assign constant values that are equal to or greater than this value.
Sample Code that Manages Event Handling
The following code sample shows how the Mobile Designer NativeUIHelloWorld sample application manages event handling:
//see MyCanvas.java
public boolean nUIEventCallback(nUIObject object, int evt_type)
{
switch (object.nuiid)
{
case NUIID_START_PROGRESS:
if(evt_type == EVT_TRIGGER)
transitionToView (main_view, onCreateEndView());
break;
case NUIID_END_BACK:
if(evt_type == EVT_TRIGGER)
transitionToView (main_view, onCreateStartView());
break;
}
return true;
}
Setting a Unique Identifier for NativeUI Objects So that You Can Identify Them When Listening for Events
When an event occurs, the NativeUI system passes the NativeUI object that generated the event and the event type to the event listener. Each NativeUI object has a unique identifier. This unique identifier is the nuiid value that the application passed to the constructor when creating the NativeUI object. In this example that uses NUIID_START_PROGRESS, the following code shows the NUIID_START_PROGRESS unique identifier:
//Specify the ID for the start progress button.
//Use any number as long as it is unique.
public static final int NUIID_START_PROGRESS = 0x01020101;
 
//After specifying the ID, in onCreateStartView()
start_view.add(new nUIButtonElement(NUIID_START_PROGRESS, "Progress");
Tip:  
If you are not concerned about events for a NativeUI object, specify a -1 for the nuiid value that you pass to the constructor.
Return Values from Event Processing
After an application handles an event, it should return true or false to indicate whether the NativeUI system should perform the default behavior for the event. In most cases, the application should return true to indicate that the NativeUI system should perform its default behavior for the event.
Copyright © 2007-2016 Software AG, Darmstadt, Germany.

Product LogoContact Support   |   Community   |   Feedback