I’ve to evaluate some mobile technologies and have one question.
We have webapp. It’s javascript on client which gets xml from our server with our proprietary format of view. App transforms it, and view html.
We’d like to go native on Android – our app would get those xmls from webservice over http (it’s possible to change it format) and create view.
Is it doable? Is it doable in some sufficient way?
I know I can create layout in Java and with some xml format. Can I load those xml dynamically from the web and use them to inflate layout (In tutorials those xmls are in the resources only)? Or have I to parse our xml and call appropriate Java methods – would be that solution efficient?
The XML in the layout folder of the resources is converted at compile time, so loading after the fact won’t help.
You can still dynamically parse the XML and programmatically construct the layout from the XML, you could probably get away with just having an Android version of the javascript you already have to transform your proprietary format – but that depends on your format.
It won’t be as efficient in terms of speed (a lot of that depends on your networking and caching code but still a bit on your view construction code) but it will save on installation space and allows you to remotely update the view without needing to release a new version of the app.
Edit, expanded and added some code:
You can inflate any layout resource xml file into a view which you can insert into another view if you choose, take a look at LayoutInflater to inflate the view and then just use a ViewGroup extending view (like LinearLayout, or RelativeLayout) and add to it.
A quick example of some code:
It’s clunky, missing a lot of formatting but provides a basic mechanism to add one view to another.
And as an example of using layout inflater:
I would suggest using null and false as the last two parameters as you’re going to be adding it to a specific view yourself later.