views:

366

answers:

2

I'll preface this with, I've just started learning Android so be gentle. I come from an ASP.NET / Silverlight background so I was looking for something along the lines of controls.

I want to reuse a layout (a ListView item template) in other layouts.

Such that in my other layouts I can just add <myListItem /> to show it.

Is this, or anything like it possible? or are there better ways?

+2  A: 

Yes, Android allows you to build custom, reusable views. Here is some basic documentation on how it works.

Erich Douglass
It happens that Dan's answer was more where my focus was but this is a valuable answer too. +1
TreeUK
Not a problem. Glad you could find an answer for your question!
Erich Douglass
+3  A: 

This is very possible; you just need to use the <include /> tag. Basically, you put your layout in a file, then you do:

<include layout="@layout/my_list_item_template" />

Romain Guy goes into detail on how to use it here: http://www.curious-creature.org/2009/02/25/android-layout-trick-2-include-to-reuse/

(I am assuming that what you want is a reusable layout, not a custom component. The difference being, a reusable layout is like reusing snippets of standard components, whereas a custom component is used when you need to extend the functionality of a particular widget, like a TextView or Button. If you want a custom component, then you'll have to do a lot more legwork to Erich Douglass' answer for more on that.)

Daniel Lew
Just what I was looking for, thanks!
TreeUK