Neznajka
Neznajka

Reputation: 35

Sorting Images on Android

I need images to be sorted by folders. like drawable/Photos, drawable/items, drawable/photos. and put each folder to the registry or at least find way to get them out of there. all I want is something close to php like "../img/photos/photo0.jpg". is there way to do something like this. and folder with Images must contain in apk file.

possible solutions is make link in the R file but I didn't find how to do it, other solution is find command with logic like I will show you here:

ImageView img = (ImageView)CloningTable.findViewById(R.id.img); 
String ImgPath = "com.test.test/img/img0.jpg";
img.setImageDrawable(Drawable.createFromPath(ImgPath));

OR

ImageView img = (ImageView)CloningTable.findViewById(R.id.img);
String ImgPath = "com.test.test/img/img0.jpg";
img.setImageResource(ImgPath);

please say me the best way to handle it. AND specify if it contain path how I can know path the file lies in.

File ImgFile = new File("test/test.jpg");
TextView testtext = (TextView)CloningTable.findViewById(R.id.testtext);
if (ImgFile.exists()) {
    test.setImageBitmap(BitmapFactory.decodeFile(ImgFile.getPath()));
    testtext.setText("asdasuidjasdk");
}

can any one say Why programm can't find file and file exist 100% = /?

filepath: Project> assets/test/test.jpg


found solution: Android Show image by path

Upvotes: 0

Views: 522

Answers (2)

Luke Vo
Luke Vo

Reputation: 20658

In this case, you should put resources in assets folder, and you can access them by path!

So if you want to save the path string, the best way is creating a class, with 2 variants: 1 Bitmap to store data, and 1 String to store the path.

If not, just create a String array that you may access when you want.

In both case, you need to put the path into the Path String storage before you load the image.

Hope I understood your question.

EDIT: Final answer that meet your requirement:

There's no path for drawable, they are all converted into ID. If you put in asset folder, just call it by their name. For example, you have "Test.bmp" in asset folder, its path is "Test.bmp". If you have "SubTest.bmp" in "TestFolder" in asset folder, its path is "TestFolder/SubTest.bmp". Sorry for long time, I had to sleep, it was mid night at my time zone.

Upvotes: 0

Aleadam
Aleadam

Reputation: 40391

It's hard to understand why you need to sort resources that will be static in your APK, but you should not access them directly using paths, but using the API for that purpose.

Take a look at the topics in the dev guide here:

http://developer.android.com/guide/topics/resources/accessing-resources.html

http://developer.android.com/guide/topics/resources/drawable-resource.html

Those will teach you how to access the resources. To create Bitmaps from them, the easiest way is to use the BitmapFactory class

Remember, you know which resources the APK has at building time, so you can work around it. If you want to work with Bitmaps created at runtime, then use the data storage methods instead.

Upvotes: 1

Related Questions