I'm trying to write a library that can be shared as a JAR file. This library will include an Activity and I'd like to include the layout in the JAR. Since it doesn't seem possible to include resource files in a JAR and I don't want the end-users to have to include these files themselves I was thinking it would be a nice hack to include the XML as a String then manually inflate it. Does anyone know if this is possible? Any other ideas?
Asked
Active
Viewed 1,936 times
1 Answers
3
Native layout XML files are converted to a binary form, and include resource IDs baked at build time.
However since all GUI elements can be instantiated at runtime, you could probably roll your own inflater with an XML parser and a bit of reflection.
It may be easier in your case just to build the activity view programatically.

Jim Blackler
- 22,946
- 12
- 85
- 101
-
Based on my research since asking the questions, that's the conclusion I'd came to as well (building the views programatically). I'm still hoping for a better solution though ;) – Jeremy Logan Apr 05 '10 at 07:32
-
2There are two tiers of "better solution". Right now, you're stuck with either shipping the layout file for the reuser to copy or you have to avoid resources altogether. I am working on a reusable component packaging system that will help with this, but it's a month or two away from release at this time. – CommonsWare Apr 05 '10 at 12:21
-
1It'd be nice if there was something that would "compile" the XML layout into Java source. – Jeremy Logan Apr 06 '10 at 01:24