> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/xamarin/viewer/events.md).

# Viewer events

Learn how to detect and respond to events in Xamarin.Android using Apryse SDK. Add event listeners to PdfViewCtrlTabHostFragment2 and PdfViewCtrlTabFragment2 for enhanced document viewer functionality

Apryse SDK allows you to detect and act in response to various events.

## Viewer event listener & handler in Xamarin.Android

{% hint style="info" %}
**This tutorial only applies to Xamarin.Android.**
{% endhint %}

## PdfViewCtrlTabHostFragment2 events

Event listeners can be added to a [`PdfViewCtrlTabHostFragment2`](https://sdk.apryse.com/api/xamarinandroid/tools/api/pdftron.PDF.Controls.PdfViewCtrlTabHostFragment2.html) to listen for document viewer events. This can be done by adding a `TabHostListener` using `PdfViewCtrlTabHostFragment2.addHostListener()`. Some useful events include:

| Event                 | Description                                                                                     |
| --------------------- | ----------------------------------------------------------------------------------------------- |
| `onTabDocumentLoaded` | Called when document associated with a tab is loaded.                                           |
| `onTabHostShown`      | Called when the tab host has been shown.                                                        |
| `onTabHostHidden`     | Called when the tab host has been hidden.                                                       |
| `onLastTabClosed`     | Called when the last tab in the tab host has been closed, and therefore there are no more tabs. |
| `onTabChanged`        | Called when a new tab has been selected excluding the initial tab.                              |
| `onNavButtonPressed`  | Called when navigation button has been pressed.                                                 |

{% hint style="info" %}
**For a full list of events, please take a look at the TabHostListener API documentation.**
{% endhint %}

## PdfViewCtrlTabFragment2 events

Similarly, [`PdfViewCtrlTabFragment2`](https://sdk.apryse.com/api/xamarinandroid/tools/api/pdftron.PDF.Controls.PdfViewCtrlTabFragment2.html) has its own events and and you can listen for them by adding a `TabListener` using `PdfViewCtrlTabFragment2.setTabListener()`. Some useful events include:

| Event                    | Description                                          |
| ------------------------ | ---------------------------------------------------- |
| `onTabDocumentLoaded`    | Called when the document has been loaded.            |
| `onOpenAddNewTab`        | Called when a new tab has been opened.               |
| `onTabPaused`            | Called when the tab fragment is paused.              |
| `onDownloadedSuccessful` | Called when download successfully has been finished. |

{% hint style="info" %}
**For a full list of events, please take a look at the TabListener API documentation.**
{% endhint %}

## ToolManager events

Touch events, annotation events, quick menu events and tool change events in the document viewer are all managed by the [`ToolManager`](https://sdk.apryse.com/api/xamarinandroid/tools/api/pdftron.PDF.Tools.ToolManager.html). You can learn more about `ToolManager` events [here](/xamarin/annotation/toolmanager-events.md#android).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/xamarin/viewer/events.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
