Good afternoon, I need to create a view dynamically, that is, not to transmit a link to a static xml file when creating, but dynamically, for example, passing a String in which xml is already stored for the view.
I tried to do this:

XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); XmlPullParser xpp = factory.newPullParser(); xpp.setInput(new StringReader(text)); LayoutInflater.from(context).inflate(xpp,this,true); 

But as written on developer.android.com:
For the construction of the XML files Therefore, it is not possible to use LayoutInflater with an XmlPullParser over a plain XML file at runtime.

Help solve this question and is it even possible?

  • Most likely you do not need it and your case can be solved in another way. You can create a view programmatically without xml. Describe what you want to achieve. - eugeneek
  • I need to create a view so that I can later turn it into a bitmap, in order to then print the image from the device on the map. But I just need to programmatically implement the formation of xml at runtime and the creation from it view - Ivan Black

1 answer 1

Standard methods do not do this, but judging by the answer to enSO

https://stackoverflow.com/a/21657847/5479247

There is a workaround through reflection.
There is a link to GitHub with a ready method that creates the "correct" parser for xml markup.