Inflate XML file from internal memory

…衆ロ難τιáo~ 提交于 2019-12-03 17:11:47

You cannot inflate that file using LayoutInflater. First, you can only inflate layout resources, not arbitrary files. Second, based on the description in your first paragraph, it is not a layout file in the first place.

If you want to parse arbitrary XML, use the DOM, SAX, or XmlPullParser.

From the Android view API:

it is not currently possible to use LayoutInflater with an XmlPullParser over a plain XML file at runtime.

A solution might be to pre-process XML files before. You must compress the XML file in the same way the Android SDK does at build time:

view inflation relies heavily on pre-processing of XML files that is done at build time

I guess you will have to call XmlPullParser.setInput to load your pre-processed XML, and then pass the XmlPullParser to View.inflate. I hope it is possible to do this kind of stuff even for content that is not in the APK.

I am very interested in any solution you can find. Please let me know if you find or create a prototype! This would be a decisive step towards creating a plugin architecture for my Open Source app.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!