Now you can Subscribe using RSS

Submit your Email

Tuesday

Add Multiple Tags to a button

Vishal Shrestha
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(R.id.*) .

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"?>

<resources>
    <item type="id" name="position" />
    <item type="id" name="color" />
</resources>

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


setTag(R.id.position, object1);   //position is already defined above in the 
                                                                            //resouce
setTag(R.id.positon, object2);    //position is already defined above in the 
                                                                            //resouce

Vishal Shrestha / Author & Founder

A developer by profession, a born Adventurer. I mainly do Android but like to get my hands dirty with web development and a little bit of Python. I would't rather go on a Trek than a party and you can find me having a few rounds with the heavy bag to let out the steam ;)

For Business info : My Portfolio Site.

0 comments:

Post a Comment

Coprights @ 2017 | The Code City by Vishal Shrestha Vishal Shrestha