views:

231

answers:

1

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?

+1  A: 

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
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 ;)
fiXedd
There 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
It'd be nice if there was something that would "compile" the XML layout into Java source.
fiXedd