Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set multiple tags for an object in android

Tags:

android

My research I have found that I need to use below methodology

textView.setTag(1,object1);
textView.setTag(2,object2);

What i tried::

  • i tried to pass a list in place of object but couldn't get it to work.
  • I understand it has to be an object, if so how to make that object. any samples would help
like image 409
Devrath Avatar asked Jan 24 '26 03:01

Devrath


1 Answers

If need to add multiple tag into one view the you have to define the id for every tag in string.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 :

Section mSection=(Section)rowView.getTag(R.id.section);
String isOpen=(String)rowView.getTag(R.id.hide_show);
like image 105
Arun kumar Avatar answered Jan 25 '26 18:01

Arun kumar