Understand PDF form events in Android SDK
In Nutrient Android SDK, form events are accessible through the FormManager interface, which is implemented by the PdfFragment. There, you can find the following listeners for subscription:
| Listener | Description |
|---|---|
OnFormElementClickedListener | Listener for form element click events. |
OnFormElementDeselectedListener | Listener for form element deselection. |
OnFormElementEditingModeChangeListener | Listener for form element editing mode enter/exit. |
OnFormElementSelectedListener | Listener for form element selection. |
OnFormElementUpdatedListener | Listener for form element updated events. |
OnFormElementViewUpdatedListener | Listener for form element view updates — validation, contents of the view changed, etc. |
Reacting to Clicks on form elements
PdfActivity and PdfFragment support form filling. The default tap behavior depends on the field type:
- Push button — Executes the form element’s
Action. For details, refer to the PDF actions guide. - Signature field — Starts signing. For details, refer to the signing forms guide.
- Other fields — Selects the form element and enters form editing mode.
To customize tap behavior, register OnFormElementClickedListener with addOnFormElementClickedListener() on PdfFragment:
fragment.addOnFormElementClickedListener { formElement -> when { formElement.type == FormType.SIGNATURE -> { // Implement custom signature flow here.
// By returning `true`, you intercept the event and prevent Nutrient from showing the signature UI itself. true } formElement.type == FormType.PUSHBUTTON -> { // Implement custom push button click handling.
// By returning `true`, you intercept the event and prevent Nutrient from executing the button's action. true } else -> { // This click event isn't interesting. Return `false` to let Nutrient handle this click event. false } }}fragment.addOnFormElementClickedListener(formElement -> { if (formElement.getType() == FormType.SIGNATURE) { // Implement custom signature flow here.
// By returning `true`, you intercept the event and prevent Nutrient from showing the signature UI itself. return true; } else if (formElement.getType() == FormType.PUSHBUTTON) { // Implement custom push button click handling.
// By returning `true`, you intercept the event and prevent Nutrient from executing the button's action. return true; }
// This click event isn't interesting. Return `false` to let Nutrient handle this click event. return false;});Reacting to form element selection
Users can select most form elements for interactive editing, except push buttons and signature fields. Register these listeners on PdfFragment to receive selection events:
Selecting a form element also starts editing mode. Register OnFormElementEditingModeChangeListener on PdfFragment to handle its lifecycle.
To integrate form filling into a custom activity, refer to the custom form editing UI guide.
For more information on how Nutrient Android SDK implements forms, please see our introduction to forms guide.