[android-developers] Re: How to create a View from an external XML source?
Inflation only works with an XML file that has been processed by aapt into the binary resource representation. 2009/9/14 Dmitry.Skiba dmitry.sk...@gmail.com Hm, at a first glance this is possible: several LayoutInflater.inflate methods accept XmlPullParser, and you can certanly create one for an arbitrary Reader. Dmitry On 15 сен, 06:48, Argy akri...@gmail.com wrote: I'm just wondering if I'm able to create a View from an external XML source. As I was reading, you must place the XML layout inside the res/layout and when you compile it, you can load the layout by typing setContentView(R.layouts.my_layout). What if I have this XML layout online (on a website) and I want to create the layout on runtime? Is there any way to do this? Or I have to parse the XML and create the layout (hard-coded)? -- Dianne Hackborn Android framework engineer hack...@android.com Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: How to create a View from an external XML source?
Important: For performance reasons, view inflation relies heavily on pre-processing of XML files that is done at build time. Therefore, it is not currently possible to use LayoutInflater with an XmlPullParser over a plain XML file at runtime. So I guess it has to be a pre-processed XML file and not a plain XML file. That's bad news... it would be great if there was a workaround for this one... Now I have to parse the XML myself and create the layout... Any other suggestions? Thanks, Argy On Sep 15, 8:36 am, Dmitry.Skiba dmitry.sk...@gmail.com wrote: Hm, at a first glance this is possible: several LayoutInflater.inflate methods accept XmlPullParser, and you can certanly create one for an arbitrary Reader. Dmitry On 15 сен, 06:48, Argy akri...@gmail.com wrote: I'm just wondering if I'm able to create a View from an external XML source. As I was reading, you must place the XML layout inside the res/layout and when you compile it, you can load the layout by typing setContentView(R.layouts.my_layout). What if I have this XML layout online (on a website) and I want to create the layout on runtime? Is there any way to do this? Or I have to parse the XML and create the layout (hard-coded)? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: How to create a View from an external XML source?
Hm, yes, I was wrong. So, no official way of doing it, yet. Lets hack then :) I can suggest the following: put layout in a dummy project, generate .apk from it. Program would download this apk, install it, and then query xml resource via PackageManager. Dmitry On 15 сен, 15:52, Argy akri...@gmail.com wrote: Important: For performance reasons, view inflation relies heavily on pre-processing of XML files that is done at build time. Therefore, it is not currently possible to use LayoutInflater with an XmlPullParser over a plain XML file at runtime. So I guess it has to be a pre-processed XML file and not a plain XML file. That's bad news... it would be great if there was a workaround for this one... Now I have to parse the XML myself and create the layout... Any other suggestions? Thanks, Argy On Sep 15, 8:36 am, Dmitry.Skiba dmitry.sk...@gmail.com wrote: Hm, at a first glance this is possible: several LayoutInflater.inflate methods accept XmlPullParser, and you can certanly create one for an arbitrary Reader. Dmitry On 15 сен, 06:48, Argy akri...@gmail.com wrote: I'm just wondering if I'm able to create a View from an external XML source. As I was reading, you must place the XML layout inside the res/layout and when you compile it, you can load the layout by typing setContentView(R.layouts.my_layout). What if I have this XML layout online (on a website) and I want to create the layout on runtime? Is there any way to do this? Or I have to parse the XML and create the layout (hard-coded)? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: How to create a View from an external XML source?
Argy wrote: What if I have this XML layout online (on a website) and I want to create the layout on runtime? Is there any way to do this? No, sorry. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy _Android Programming Tutorials_ Version 1.0 In Print! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: How to create a View from an external XML source?
Yea, look at class LayoutInflater. It explains why pulling the XML from outside will not work... On Sep 14, 8:31 pm, Mark Murphy mmur...@commonsware.com wrote: Argy wrote: What if I have this XML layout online (on a website) and I want to create the layout on runtime? Is there any way to do this? No, sorry. -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy _Android Programming Tutorials_ Version 1.0 In Print! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: How to create a View from an external XML source?
Argy, One way is by, LayoutInflater inflater = (LayoutInflater) getSystemService (Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.main, true); then , in setContentView(), you can use this view... Thanks Nithin On Sep 15, 6:37 am, WoodManEXP woodman...@gmail.com wrote: Yea, look at class LayoutInflater. It explains why pulling the XML from outside will not work... On Sep 14, 8:31 pm, Mark Murphy mmur...@commonsware.com wrote: Argy wrote: What if I have this XML layout online (on a website) and I want to create the layout on runtime? Is there any way to do this? No, sorry. -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy _Android Programming Tutorials_ Version 1.0 In Print! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: How to create a View from an external XML source?
Hm, at a first glance this is possible: several LayoutInflater.inflate methods accept XmlPullParser, and you can certanly create one for an arbitrary Reader. Dmitry On 15 сен, 06:48, Argy akri...@gmail.com wrote: I'm just wondering if I'm able to create a View from an external XML source. As I was reading, you must place the XML layout inside the res/layout and when you compile it, you can load the layout by typing setContentView(R.layouts.my_layout). What if I have this XML layout online (on a website) and I want to create the layout on runtime? Is there any way to do this? Or I have to parse the XML and create the layout (hard-coded)? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---