1

I was interested in downloading the xml layout for UI views from a server and inflate that as an xml string.
What I see in the doc though is:

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.)

I don't really understand the highlighted part (my emphasis).
If I have some "dummy" xml file to get the XmlPullParser could I inflate my xml string?

And in general if this is impossible what alternatives are there?
I mean besides that does not require a huge learning curve like react native

qtmfld
  • 2,916
  • 2
  • 21
  • 36
Jim
  • 3,845
  • 3
  • 22
  • 47

1 Answers1

0

You can’t inflate view hierarchy from plain XML files, because of the unusual implementation of LayoutInflater. According to the source code, the following inflate methods won’t work with a simple instance of XmlPullParser.

    View inflate(XmlPullParser parser, ViewGroup root)
    View inflate(XmlPullParser parser, ViewGroup root, boolean attachToRoot)

The implementation requires that the first argument parser is an instance of class XmlBlock.Parser. The class implements interface XmlResourceParser, and the interface extends three interfaces:

Therefore, simple XmlPullParser is not enough for the inflate methods. The APIs should be:

    View inflate(XmlBlock.Parser parser, ViewGroup root)
    View inflate(XmlBlock.Parser parser, ViewGroup root, boolean attachToRoot)
qtmfld
  • 2,916
  • 2
  • 21
  • 36