Hi Lutz. Thanks for your answer. What you propose is what I tried
first in different variations:

XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
XmlPullParser xpp = factory.newPullParser();

The returned xpp is an instance of org.kxml2.io.KXmlParser and thus
cannot handle the preprocessed layout.xml which is in a binary format.
It could parse plain text xml but that won't work either (see below).
I even tried to parse the preprocessed xml with a
org.kxml2.wap.WbxmlParser which didn't work either.

Finally you can see in my message above (Mar 26) that during creation
of a widget with an AttributeSet the following line is executed:

XmlBlock.Parser parser = (XmlBlock.Parser)set;

Since I have no access to XmlBlock.Parser (which has default
protection) I have no chance to provide a valid AttributeSet to a
widget constructor.

Daniel





On Mar 26, 4:43 pm, Lutz Schönemann
<[email protected]> wrote:
> > 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 <[email protected]> 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<[email protected]> 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
> > >
>
>
>  smime.p7s
> 10KViewDownload

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to