load file from asset whit subfolders - android

I have some problems while loading the file from the asset folder.
I wrote a code to load a txt file into a textview and everything works good.
If I try to put some order inside my txt file. I decided to put those files in subfolders in alphabetic order, because I have 800 text files. In this way my code is wrong. Is there a method to maintain the subfolders and load the file whitout specify where they are??
Thanks a lot

Related

difference between assets folder and res/xml [duplicate]

This question already has answers here:
Difference between /res and /assets directories
(8 answers)
Closed 9 years ago.
in this tutorial for "learning to parse XML data in your Android App" the author puts his XML file into the assets folder. But in other tutorials they recommend to use res/xml.
None of them explains why they took the folder they use.
What is the difference between those two folders? What is best practice? Is there a difference in performance?
The res folder is used to put authorized resources files type, like layout(xml), drawable (png, jpg, xml), raw (mp3, ogg), etc... In the assets folder, you can put all files types you want (txt, avi, png, docx, xyz, ext, asm, ....).
Check this : Android Projects Structure
1) assets/
This is empty. You can use it to store raw asset files. Files that you save here are compiled into an .apk file as-is, and the original filename is preserved. You can navigate this directory in the same way as a typical file system using URIs and read files as a stream of bytes using the AssetManager. For example, this is a good location for textures and game data.
2) res/
Contains application resources, such as drawable files, layout files, and string values. See Application Resources for more information.
anim/
For XML files that are compiled into animation objects. See the Animation resource type.
color/
For XML files that describe colors. See the Color Values resource type.
drawable/
For bitmap files (PNG, JPEG, or GIF), 9-Patch image files, and XML files that describe Drawable shapes or Drawable objects that contain multiple states (normal, pressed, or focused). See the Drawable resource type.
layout/
XML files that are compiled into screen layouts (or part of a screen). See the Layout resource type.
menu/
For XML files that define application menus. See the Menus resource type.
raw/
For arbitrary raw asset files. Saving asset files here instead of in the assets/ directory only differs in the way that you access them. These files are processed by aapt and must be referenced from the application using a resource identifier in the R class. For example, this is a good place for media, such as MP3 or Ogg files.
values/
For XML files that are compiled into many kinds of resource. Unlike other resources in the res/ directory, resources written to XML files in this folder are not referenced by the file name. Instead, the XML element type controls how the resources is defined within them are placed into the R class.
xml/
For miscellaneous XML files that configure application components. For example, an XML file that defines a PreferenceScreen, AppWidgetProviderInfo, or Searchability Metadata. See Application Resources for more information about configuring these application components.
The difference between "resources" and "assets" isn't much on the surface, but in general, you'll use resources to store your external content much more often than you'll use assets. The real difference is that anything placed in the resources directory will be easily accessible from your application from the R class, which is compiled by Android. Whereas, anything placed in the assets directory will maintain its raw file format and, in order to read it, you must use the AssetManager to read the file as a stream of bytes. So keeping files and data in resources (res/) makes them easily accessible.
For details you can see following links :
Link1,
Link2

HorizontalScrollView Getting Images from /drawable folder

I am using HorizontalScrollView in order to create some Gallery-like option and right now I am getting the images from an folder in the external drive. But I figured that I don't need, also shouldn't do that since the images I wanted to show is predetermined images. So I will simply change the directory to the drawable folder but I am not sure which path to go. So right now I am getting the directory with this:
String path1= Environment.getExternalStorageDirectory().getAbsolutePath();
I found two more methods for directory retrieval but I am not sure which one to use.
String path2 = Environment.getDataDirectory().getAbsolutePath();
String path3= Environment.getRootDirectory().getAbsolutePath();
First one returns "/mnt/sdcard", second returns "/data", third one "/system".
Which one should I use in order to reach /drawable folder inside this way?
Which one should I use in order to reach /drawable folder inside this way?
None of them. Those are all for files on the filesystem. Drawable resources are not files on the filesystem.
Use getResources().getDrawable() to retrieve a Drawable given its ID (e.g., R.drawable.foo).

How to set the standard folder from which to read the file

I'm trying to create a small puzzle game. My problem is to set the folder where the app reads pictures. Is possible to create in the drawable folder another folder called "images", and insert in this folder the pictures that the app reads ?
I'm using:
((SelectImagePreference) findPreference(IMAGE_SOURCE)).setCustomLocation(data.getData());
Use assets folder http://www.wiseandroid.com/post/2010/06/14/Android-Beginners-Intro-to-Resources-and-Assets.aspx

How to set icon for a file?

I am creating different types of Files. For example File extension as.txt, .doc, .xml, .java, .jpg, .png, and etc. How to set the icon to be matched with the files. For example i am creating one pdf file. How to set pdf icon to that pdf file.
You dont have to explicitly set icons for the files, unless you are creating file with your own extension.
The operating system will understand the file type and binds the icon accordingly.
That is why in windows, if you manually change a file's extension, the icon changes automatically. Same case applies to Android also.
If you want to create different files via your android app & want to show the files list along with icon as we can see it in Windows OS, then you have to put all different images of each file extension in drawable folder. example- pdfImage.png, jpgImage.png, pngImage.png etc. Now you have to process the file name to determine the file extension runtime. then update your iconView (an ImageView item) like:
iconView.setImageBitmap(bitmap); // bitmap is the Bitmap image
or
iconView.setBackgroundResource(R.drawable.pdfImage_icon);

How to create a new folder inside the drawable folder and reference an image from it?

I am working on an ANDROID project where I have a lot of images and I want to organize it.
So I need to create folder inside the drawable folder.
But I don't know how to reference it in my program.
For eg: I have an image named "image.png" and I want to place it in drawable/myicons/image.png
or anywhere inside the res folder.
This is duplicate question
You can not create folder inside drawable
the resources mechanism doesn't support subfolders in the drawable directory
However you can use the assets folder and have sub directories in there and load images that way.

Categories

Resources