views:

259

answers:

1

I was wondering how everyone re-uses android layouts and components? Do you do the old copy/paste the existing code into the project, or is there a way to include the layouts and components into a jar file for re-use?

EDIT: For example if I have a list view, maybe I have another view that I am using for each list item in the listview, it could have an icon, and maybe a header row, and then a row with more details. While it is not hard to create this, it would be nice to be able to create this once generically and re-use it in different projects.

+1  A: 

If you're using the layouts in the same project, the "include" tag will work:

<include android:id="@+id/the_id" layout="@layout/my_layout_to_include" />

for more information: http://www.curious-creature.org/

As for re-using across projects, I would suggest creating a custom view and distributing that in a jar file.

Ralphleon
Ralphleon, is there a way to easily distribute the associated layout files in that jar file as well (assuming your custom view used layout files)? Seems like you'd have to package them separately and have the user extract them into the res directory, no?
Mike
I see the same problem w/ this, has anyone tried putting them in a jar w/ resources like icons, layouts, etc.
broschb