Add Multiple Tags to a button

If you want to add a single tag, then you can simply do this-
setTag(1, object1); Or setTage(object1);
where 1 is the key, you can also do this without a key for just one tag and then use it like –

button.getTag(1); or button.getTag() if you haven’t set a key.

NOTE- The method above will not work with multiple tags, do this adding for multiple tags-

Google recommends to use unique id- “The specified key should be an id declared in the resources of the application to ensure it is unique.”

Every resource you create can have an ID, a string (R.string.*, or a layout (R.layout.*) or an individual View(*) .

To create a resource ID, which can be used just as the ones you set in XML using +id, add the create an XML with any name in res/value with the following code-

<?xml version=”1.0″ encoding=”utf-8″?>

    <item type=”id” name=”position” />
    <item type=”id” name=”color” />

You can create as many items as you wish with type id and unique name and use it with setTag as-

setTag(, object1);   //position is already defined above in the 
setTag(, object2);    //position is already defined above in the 

Don’t miss these tips!

We don’t spam! Read our privacy policy for more info.

You’ve been successfully subscribed to our newsletter! See you on the other side!

Sharing is caring!

Leave a Comment

Your email address will not be published.

Exit mobile version