The point is now: Android already has this user interface description
(layout.xml) and the code which inflates such a description (in
preprocessed form) to a user interface. It would be awesome to reuse
this code!

You can use that LayoutInflater to create the tree of views and attach it to your Activity. I found some code inside the PackageInstaller to load the layout from the resources but you can also use an 'external' xml.


--- snip ---

View contentView;

XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
XmlPullParser xpp = factory.newPullParser();
xpp.setInput(new FileReader("/path/to/layout.xml"));

LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
contentView = inflater.inflate(xpp, null);

setContentView(contentView);

--- snip ---

This code isn't tested!!! That's only the way I think it should work.

Lutz



Thanks. Daniel


On Mar 23, 6:25 pm, droozen <droozenr...@gmail.com> wrote:
We might have to know why you want to build this way. There could be
other possibilities, including using a much simpler xml that you could parse yourself and add UI elements programmatically. Or have a variety
of layouts available that you could set, depending on a value you've
downloaded, though I get the feeling you want something more dynamic
than that.

On Mar 23, 2:10 am,Daniel<daniel.kro...@gmail.com> wrote:

Hi all,

Q: What is the recommended way to build user interfaces on the device
based on layouts provided by a server at runtime?

I am aware of this:
<snip source="http://developer.android.com/reference/android/view/
LayoutInflater.html">
For performance reasons, view inflation relies heavily on pre-
processing of XML files that is done at build time. Therefore, it is
not currently possible to use LayoutInflater with an XmlPullParser
over a plain XML file at runtime; it only works with an XmlPullParser
returned from a compiled resource (R.something file.)
</snip>

I could imagine these possibilities:
- Parse XML by myself and build the ui tree. (Seems inappropriate to
me since there is already maintained code which is able to do this.)

- Transform XML on server to a simpler format which is cheaper to
parse on the device. (Inappropriate  as above.)

- Preprocess the XML layout on the server the same way the build does.
Transmit it to the client, and then try to load it. But how?
android.content.res.XMLBlock is hidden (@hide) and I don't know how
to
classify the stuff in package com.android.layoutlib.bridge.

Any help would be appreciated.
Daniel
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---



Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to