Event Handling
MicroUI generates integer-based events that encode the low-level input type and some data. The application can handle these events in the handleEvent() method.
The handleEvent Method
Every class that extends Widget inherits the handleEvent() method.
Add custom event handling by overriding the handleEvent() method of a widget.
As an example, here is the event handling of the Button class:
@Override public boolean handleEvent(int event) { int type = Event.getType(event); if (type == Pointer.EVENT_TYPE) { int action = Pointer.getAction(event); if (action == Pointer.PRESSED) { setPressed(true); } else if (action == Pointer.RELEASED) { setPressed(false); handleClick(); return true; } } else if (type == DesktopEventGenerator.EVENT_TYPE) { int action = DesktopEventGenerator.getAction(event); if (action == PointerEventDispatcher.EXITED) { setPressed(false); } } return super.handleEvent(event); }
It’s important to note that only widgets that are “enabled” will receive input events. One can enable a widget by calling setEnabled(true).
In the Button class, the click triggers an action defined by the registered OnClickListener.