Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View.setTag - need multiple keys: resourceIDs

Tags:

android

view

I'm creating a custom View to be included in a class library. I need to add multiple tags to subviews that I am creating dynamically (in code, not xml), so this requires that I add use: View.setTag(int key, Object tag).

The key needs to be an id defined in the project R file, but since all of my views are dynamically created and the code is going into a library for use in other projects, I don't have a hardcoded resource id on hand to use. Is there any way to discover a couple of defined resource ids programatically, or to define some programatically? Or am I going about this all wrong?

Thanks

like image 616
noobler Avatar asked Aug 16 '26 02:08

noobler


1 Answers

Keep in mind that you can add any object as a tag. If the data you're adding to the view is dynamic, then the easiest thing to do would be to add a Hashtable to the View as the tag. Then add all the key/value pairs you want to that Hashtable. On the other end, (the code processing the tag), you can iterate over the values by casting the View's tag back into a Hashtable, and iterating over Hashtable.keys().

like image 193
Alexander Lucas Avatar answered Aug 18 '26 17:08

Alexander Lucas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!