Downloading an android layout from the internet - android

I would like ask if there's a way to download an android layout from the Internet into the "res/layout" folder.
I was thinking in getting the file using an HttpUrlConnection and a FileOutputStream, like discussed in here Android download binary file problems but I can't fgure out how to put it into the "res/layout" folder.
Thanks!

Unfortunately the layouts in your 'res' directory are compressed at build time and include baked-in resource IDs that match your pre-built R.java. So it wouldn't be possible to take a new layout file at runtime and inflate it in the same way.
However layouts can be built up programatically (new Button() and so on), so you could probably make an XML format and reader that was quite similar to the standard layout format.

Related

Load large XML files

I have an xml file (contains images) in the file. The file size is about 50M.
When i read it in flex
on iOS it read well, no problems. Everything is ok
but on Android always it gives me error #1085.
The file and code are the same in Android and iOS.
The XML file is valid - I have tested it on XML validator.
Can anyone tell me what to do?
Check the encoding of the file... it might be that the file is saved with a different encoding on android.

Android Anim Folder

In my Android SDK folder on Windows I have found anim folder with lot of different .xml files, but in my application in eclipse when I try to load one it only shows me few of them. How can I access those rest without creating custom XML file and pasting the code into it? I mean can I access them like R.anim.file.xml ?
Yes. There is an R.class file precompiled and given for you by the Android SDK. You can simply refer to it by android.R.anim.slid_in, android.R.anim.slide_out etc.
Find more out about it here: http://developer.android.com/reference/android/R.anim.html

Data in XML: where to place it

I am trying to design a new Android application.
For that application I will have an XML file that will be located somewhere on the server. This file will be generated from the mySQL DB.
For now (developmental phase) I got a simple and small XML file that I need to put in the Android Eclipse project in order to read it and present the data on the phone.
I just tried to put this file in res/values, but compiler gives me an error: "Invalid start tag".
Looking through the stackoverflow and google I see a lot of different answers and google even give me an answer of how to parse xml file on Android. ;-)
So is there a "standard" place where such XML file goes in Android Eclipse project? Think about it as the data that is read from the DB.
Some answers are to place it in the res/xml folder. I just made a brand new Android project and I don't see such folder in it. Do I create one? Shouldn't it be done automatically?
Some says you need to put it the res/raw folder. Again it is not present in the Eclipse project. Do I make one? Shouldn't it be present already?
Please clarify.
Shouldn't it be present already?
It doesn't have to. There can be thousands of folders inside res/ folder. You don't want to have them all at first.
Do I make one?
Yes. Add folders when you need them.
Some answers are to place it in the res/xml folder.
Some says you need to put it the res/raw folder.
The difference between these folders is that files inside raw stay the same you put them and inside xml are parsed when APK is created and put there in a binary, optimized form, similar to what happens to layouts, AndroidManifest and other.

How to load an xml file from android's assets folder by name

I am trying to load an xml file located in the /assets folder of an android project by name using this method:
getAssets().openXmlResourceParser("thefilename.xml");
However, executing this code always throws a "FileNotFound" exception, even though the file is located in the /assets folder and is with the correct file name.
Now, I have not put the file in the /res/xml folder because I really need to be able to 1. edit the file right on the device itself and most importantly 2. add new xml files to the application without issuing an update, to allow for easy user modifications.
Thanks in advance.
I think what you are looking for is either getAssets().open("thefilename.xml") or getAssets().openFd("thefilename.xml") depending on what the end use of the file is. You can see from Dianne's response in this post awhile back that openXmlResourceParser() is not really usable just to gain access to files in the assets/ directory: http://goo.gl/2KfgT
From there you will have a stream that you could feed into a SAXParser or do whatever else you choose.
Side Note: On the points you mentioned you really can't edit files directly in assets/ or add new files to assets/ at runtime. You will need to work with files on either internal or external storage to do those things. You probably already knew that, but I thought I'd mention it.
Hope that Helps!

Why won't R update for a linked XML file?

I have two XML files located in res/xml/. One file is a normal XML file located in that directory called myfile.xml and I can access it normally as R.xml.myfile.
Eclipse allows you to link files in from other locations. I have another XML file that is linked in from another drive. No matter what I do, i can not access this file by R.xml.newfile. I've even tried a DTD file, and isn't available via R either.
Am I doing something wrong, or is this some kind of bug?
No matter what I do, i can not access
this file by R.xml.newfile. I've even
tried a DTD file, and isn't available
via R either.
If the "linked" file is not in your res/ directory tree, aapt will not find it. If you can get Eclipse to set up "linked" files as symlinks in Linux/OS X, it might work. Or, you can skip the Eclipse "linked" concept and set up the symlink yourself. Or, you can create your own build script to copy the file from its existing spot to your project's res/ directory.
Well if the file is not in res or assest folders or inside your project how would it be available when the application is going to execute on actual device.
If the requirements remain same try accessing the xml file generated by another program as a network resource
use SAX Parser to regain the XML data, i dont know about DTD, but i prefer to use SAX or DOM to access a XML file. Sorry cant paste the code here since the SAX uses lot of classes, so tell me whether you need it or not

Categories

Resources