2

Before I ask the question, allow me to paint a picture.

Say (for whatever reason you fancy) that instead of putting your xml layout in the typical res/layouts folder, we instead put it in the res/assets folder. This can be for any reason at all, but you are doing this.

How would you then go about inflating that xml file to a view. You cant simply call View.inflate(context, r.assets.yourview, false) because when the compiler builds your app, it does not assign R. values to the assets folder. Consider it your own little space to do what you want with.

The question here is, how do you go about getting an xml file into a view. Or maybe, how does LayoutInflater or View.Inflate (which uses LayoutInflater) go about making a view from an xml file?

miversen33
  • 573
  • 5
  • 19

1 Answers1

2

If I understood you correctly, you want to dynamically load XML submission? (from .xml file)

Why do not you use LayoutInflater.inflate(XmlPullParser parser, ViewGroup root)

http://developer.android.com/reference/android/view/LayoutInflater.html

user2413972
  • 1,355
  • 2
  • 9
  • 25
  • You sir nailed it. i was looking in the source but must have missed that. Thank you! – miversen33 Oct 23 '15 at 02:15
  • though i do have to ask. If, staying with the propsed situation above, how would I get the XmlPullParser from the xml file in the assets folder? I cannot seem to find a way to do that, only getting the file loaded via input stream. – miversen33 Oct 23 '15 at 02:42
  • If I helped you, you can put the + and mark my answer, as right. From assets can create input stream. http://stackoverflow.com/a/14515873/2413972 – user2413972 Oct 23 '15 at 13:04
  • I understand how to load the input steam. I'm more asking how, how do I go from the input steam to the xmlpullparser – miversen33 Oct 23 '15 at 18:25
  • I dont think you understand. I know how to retrieve the file saved in the asset folder, to an InputStream. I fully understand this. But I do not know how to get from the InputStream object to the XmlPullParser object. You dont just cast the InputStream object over. I dont know how to get the object from the InputStream. – miversen33 Oct 23 '15 at 21:47
  • I gave you a link to the answer to this question. If you do not understand, put me + and create a new question. – user2413972 Oct 23 '15 at 21:49
  • I was viewing on my phone and it was a bit harder to read. Thank you for the link, it is indeed correct. – miversen33 Oct 23 '15 at 21:53