TextView myText = findViewById(R.id.my_text); myText.setTag("exampleTag");
ImageView myImage = findViewById(R.id.my_image); myImage.setTag(R.string.tag1, "firstTag"); myImage.setTag(R.string.tag2, "secondTag");
LayoutInflater inflater = LayoutInflater.from(context); View myLayout = inflater.inflate(R.layout.my_custom_layout, null); myLayout.setTag(myCustomObject);This example shows how to set a custom object as a tag to a view. This can be useful when we need to associate some application-specific data with a layout. The setTag() method is provided by the View class of the android.view package library.