-1

For business reasons, I have to capture the ID's of Views in my application. Since I don't want the ids to change over multiple deployments, I have created ids.xml and public.xml as described here How to add id to public.xml?

I have about 200 ids on the app, and I need to capture only about 150 of those. My question is, should I refer to all 200 ids in my ids.xml and public.xml OR just refer to the ones I need (the 150) would be good enough? Thank you.

Community
  • 1
  • 1
user1005585
  • 285
  • 5
  • 17
  • 1
    "For business reasons, I have to capture the ID's of Views in my application" -- that sounds very strange. After all, you do not create all the views yourself (except in very trivial apps) and therefore do not have control over their IDs. – CommonsWare Jan 23 '13 at 14:45

1 Answers1

1

These IDs are dynamic, and therefor you cannot capture them reliably (they most likely will change with each compile).

Maybe you can create custom attributes to use instead (like here: http://kevindion.com/2011/01/custom-xml-attributes-for-android-widgets/)

Bottom line, it is a bad practice to capture the ids.

I also think there is a 'Tag' attribute you can use in layout files, so you may want to try that as well.

Booger
  • 18,579
  • 7
  • 55
  • 72
  • Thank you. I read this thread http://stackoverflow.com/questions/9348614/what-is-the-use-of-the-res-values-public-xml-file-on-android as well and I went with getID(). I think I'll set tags and use getTag() instead. Thanks again – user1005585 Jan 23 '13 at 15:41