-1

I was wondering if it was possible to run an application on Android that will receive XML files during runtime, where these newly received XML files will then be rendered to the screen (will be shown as layout/view/string).

I was thinking that maybe you could add the newly received XML file to your res folder, but I don't think it'll change much since the generated R class will not be updated when the application is already compiled.

I have also thought of implementing my own XML parsing and rendering, but that would pretty much be like rewritting the entire render mechanism of Android.

Need help!

raybaybay
  • 647
  • 6
  • 16
  • 2
    You mean, like a web browser? – John Källén May 13 '14 at 17:13
  • Yeah basically, the application will get XML files from another source and will render them on the screen – raybaybay May 13 '14 at 17:14
  • Have you considered writing a XML stylesheets that morph the XML you're receiving to HTML5? You could make use of all the parsers already in the browser, and focus on your writing rendering logic in JavaScript. – John Källén May 13 '14 at 17:16
  • Please explain in greater detail what "render them on the screen" means. – CommonsWare May 13 '14 at 17:18
  • What i mean by "rendering them on the screen", is that: 1. My application will be run from a phone/tablet 2. It will then receive XML files (ex: home_layout.xml) 3. It will then display on screen the XML data using Android rendering (it should render it as if home_layout.xml was in the res folder) – raybaybay May 13 '14 at 17:21
  • Not really like a web browser, since its an application that is also in android. It would be equivalent to a Website that takes in HTML/CSS/JS files and completely changes its own layout – raybaybay May 13 '14 at 17:26
  • What is the point of this? I mean you will most likely needed different codes for downloaded layouts. What about something like this ? http://stackoverflow.com/questions/23586899/layoutinflater-performance/23587191#23587191 – Onur May 13 '14 at 17:33

1 Answers1

1

It will then display on screen the XML data using Android rendering (it should render it as if home_layout.xml was in the res folder)

LayoutInflater does not support anything but layout resources. You would need to write your own layout inflation logic from scratch. Given that you create your desired View hierarchy from the XML, the actual rendering would be no different than if the layout had been inflated from a resource.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Is it possible to parse the XML file and create the new layout/view programatically? Like RelativeLayout l = new RelativeLayout(); setContentView(l); – raybaybay May 13 '14 at 17:34
  • 1
    @user3158979: Assuming that you are doing the parsing, yes. You can create widgets and containers through their Java constructors, set properties on them using setters, wire them together into parent-child hierarchies using `addChild()`, and then use the resulting `View` hierarchy wherever makes sense. – CommonsWare May 13 '14 at 17:47