I have 16 buttons and I tag them to pair some terms set to buttons and imported from sqlite database. So, I tag them like this:
// labelForButton and tagForButto
If you need to add multiple tag into one view then you have to define the id for every tag in strings.xml
file like:
<item type="id" name="section" />
<item type="id" name="hide_show" />
After adding the key you can use these keys in java file like below:
rowView.setTag(R.id.section,mSectionList.get(position));
rowView.setTag(R.id.hide_show,"close");
This will set the tag. At the time of getting tag you need to typecast the object which originally you set like:
String mSection=(String)rowView.getTag(R.id.section);
String isOpen=(String)rowView.getTag(R.id.hide_show);
You should use the setTag(int key, Object tag) method, which also takes a second parameter key
. This will allow you to set multiple tags
on each Button
like this :
button.setTag(1,object1);
button.setTag(2,object2);
Define the key id in strings.xml
and then get it through the id
example:
In String.xml declare the following code
<item type="id" name="date" />
<item type="id" name="name" />
now set the tag like following
share.setTag(R.id.date,it.adjournDate);
share.setTag(R.id.name,it.partyName);
Share is my button name
Now finally get the tag in button where you want these values listener like this:
v.getTag(R.id.name)
v.getTag(R.id.date)
try :
button.setTag(R.id.resource_id1,obj1);
button.setTag(R.id.resource_id2,obj2);
button.setTag(R.id.resource_id3,obj3);
and to get the tags, use
v.getTag(R.id.resource_id1);
v.getTag(R.id.resource_id2);
v.getTag(R.id.resource_id3);
but, this will return only objects. you need to typecast it.