Source: https://nishanth-fern-test.docs-staging.pageloop.ai/mobile/tag-android-views

# Tag Android Views

### Why should you tag Android views?

The Whatfix Mobile SDK uniquely identifies the screen of native apps with the properties of a UI element like resource-id, tag, content-description, and more on the screen. Adding any of these properties helps in identifying the element and hence the app screen more accurately.

### How to add a resource-id to any view?

A resource-id is a unique identifier for any [view](https://data-flair.training/blogs/android-layout-and-views/). It can be added via XML.

```

<Button
        android:id="@+id/btn_ok"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Ok">
</Button>
```

---

### How to add a tag to a view?

Tags are extra information associated with a view. A tag can be added in two ways:

- Using Java
- Using XML

#### Using Java

```
button.setTag("tag_btn_ok");
```

#### Using XML

```
<Button
        android:tag="tag_btn_ok"
        android:id="@+id/btn_ok"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Ok">
</Button>
```

---

### How to add content-description to a view?

The content-description describes the purpose of a particular view.

         Info

         

For more information on content-description, see [Describe each UI element](https://developer.android.com/guide/topics/ui/accessibility/apps#describe-ui-element).

The content-description attribute can be added in two ways:

- Using Java
- Using XML

#### Using Java

```
imageView.setContentDescription("Arrow Icon");
```

#### Using XML

```
<ImageView
        android:contentDescription="Arrow Icon"
        android:tag="tag_img_arrow_icon"
        android:id="@+id/img_arrow_icon"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/arrow_icon">
</ImageView>
```
