Create a new view from a template?

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Create a new view from a template?

Postby simonhaines » Fri Nov 30, 2007 11:12 pm

Howdy,

I have a complex view that I would like to define in an XML layout resource and use as a template for dynamic creation. Something like 'createViewFromId(int)'. The Activity method findViewById(int) returns a (presumably static) object--I would like something to return a new object instance. Does anyone know how this might be achieved?

The only way I have seen to create dynamic views is to do it entirely programmatically, but I'd like the flexibility of using XML layout resources. Any ideas?

Regards,
Simon.
simonhaines
Freshman
Freshman
 
Posts: 5
Joined: Fri Nov 30, 2007 11:04 pm

Top

Solved!

Postby simonhaines » Sat Dec 01, 2007 12:27 am

I found this (from samples/app/IncomingMessage), which does the trick:

private View inflateView(int resource) {
ViewInflate vi = (ViewInflate)getSystemService(Context.INFLATE_SERVICE);
return vi.inflate(resource, null, null);
}

Hope this helps!
Simon.
simonhaines
Freshman
Freshman
 
Posts: 5
Joined: Fri Nov 30, 2007 11:04 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 4 guests