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
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( parser, ViewGroup root)
View inflate( 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( parser, ViewGroup root)
View inflate( parser, ViewGroup root, boolean attachToRoot)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.