i'm reading the android developer docs on creating custom components and one thing that's unclear, is whether you can define the layout of your component using xml and then reuse that across class libraries. like, say for instance, i want to create a class library called myComponents, and in there i want to have myTehAwesumsWidget or whatever, and i want the layout to be defined in xml, can i include that xml in the referenced class library?
Asked
Active
Viewed 2,781 times
0
-
As far as I can tell, you can't access resource directories inside of library files. This would be a major limiting factor in trying to incorporate XML, custom parameters, images or any kind of resource into your class library object. I look forward to being proven wrong though. – Charles B Oct 06 '10 at 00:23
1 Answers
1
If you replace "class library" with "Android library project", everything you describe should work just fine. Here is an Android library project that distributes a custom widget (also wrapped in a dialog and custom preference).

CommonsWare
- 986,068
- 189
- 2,389
- 2,491
-
Awesome! so the folder structure is the exact same then, and when you reference it, Android finds everything then? that's great. – bryan costanich Oct 06 '10 at 18:16
-
@bryan costanich: Resources get merged in, so it is important to choose appropriate naming conventions to avoid collisions, if you are planning on distributing the library widely. I have some notes on that here: http://andparcel.com – CommonsWare Oct 06 '10 at 18:18
-
On the topic of names... If you get a zillion errors after adding an Android library project to your project, the base error is likely a name collision in the resources. See Eclipse's "Problem" view; it usually shows the first error in the build. – cdhabecker Aug 05 '11 at 21:25