views:

48

answers:

1

Is it possible to load a layout XML at runtime and load into activity?

In my app, I have various types of data like Person, Company, City, etc; The requirement is to dynamically load the layout, find views by tags (property names like Person.name, Person.address) and then fill in data. For example, if user has selected an object of type Company, we want to load a company.xml layout, inflate it and then associate various properties (company name, company slogan, city, address, revenue) to tagged views. One possibility I see here is - each view in the layout will be associated with property-name as tag and then appropriate data will be loaded in appropriate views.

What should be the best design you would recommend?

A: 

Is it possible to load a layout XML at runtime and load into activity?

Not using standard Android layout XML files. Those have to be precompiled into your APK. The API does not support inflating layouts from anything but layout resources.

You could create your own interpreter of Android layout XML files, or roll something else similar.

CommonsWare