1

I want to load android XML layout file in my activity from sd card of my android device? Is this possible? Any help is appreciated.

Edit: Actually my requirements is to have layout on sd card so i can modify it whenever i want and the changes will show in my layout.

rajG
  • 53
  • 2
  • 7

3 Answers3

2

No,It's not possible.

To set XML file as layout in your activity you have that file in res/layout directory and also make sure it's id entry in R.java files.

Without keeping it in res/layout you can't apply it as a layout to your activity.

Basically when you put any xml layout file in res/layout then it's id entry created in

  public static final class layout 

in R.java files, And from there when you set that file as a setcontentView() of your activity or inflate it, the android nutshell make a view from that raw layout xml file and apply it to your activity.

The Holy Coder
  • 6,374
  • 8
  • 36
  • 71
1

Loading XML Layout File from SD CARD is simply impossible because

  1. XML Layout file resources need to generate id with R.java-Java Generated File which can be generated at compile time only. You can generate if you simple copy that XML Layoutfrom your SD-CARD to res/layout/ folder at time of writing your application

  2. R.java-Java Generated file is needed to wired up the Java code and XML Layout file. If you have used that XML Layout file resources e.g[Button,EditText etc..,] in your application.

Vikalp Patel
  • 10,420
  • 6
  • 58
  • 94
  • can i get xml layout file from other apk file that was already on sd card?......just trying other option – rajG Jan 04 '13 at 10:15
  • @rajG you can definitely get the xml files from another apk package. `But they are just useless in your application`. As that `XML Layout File never been complied with your application.` – Vikalp Patel Jan 04 '13 at 10:47
  • @rajG May be these link help you in some way to achieve your goal : http://stackoverflow.com/questions/1001944/android-remote-code-loading – Vikalp Patel Jan 04 '13 at 10:52
1

Not possible, because xml layouts are compiled in a specific format. You would need to compile the xml and inject it in the apk, which is not feasible on the device itself.

njzk2
  • 38,125
  • 7
  • 64
  • 103