How to access the res / drawable / "folder" folder

In my application, I have many photos that I have grouped into a folder under res / drawable. But Android does not allow me to access them through the "R". Is there a way to access these folders.

This is the im code that is used for.

ImageView iv = new ImageView(conext); iv.setImageResource(R.drawable.**smiley.666**); 

I noted a part that I can’t access.

thanks in advance

Safari

+6
source share
5 answers

No, Android does not allow subfolders under /res/drawable : Can the Android dropdown directory contain subdirectories?

However, you can add all image files to /drawable , and then access them programmatically with:

 int drawableID = context.getResources().getIdentifier("drawableName", "drawable", getPackageName()); iv.setImageResource(drawableID); 

Where drawableName is the name of the file to be extracted, i.e. myimage if the image file is myimage.jpg .

In the above code, an image resource with the identifier R.drawable.drawableName will be created.

+18
source

R.drawable.xxx is just the link that the Android SDK generates in your R.java file. You are trying to make a subfolder in your res folder. The SDK cannot create a link to any of your subfolders, you must put it in the predefined folders drawable-hdpi, -ldpi and -mdpi. If you do not know how it works. I will summarize. Android runs on many different devices with many different screen resolutions. With these three folders, you can have the same image in three resolutions, and depending on the device on which the application is running, one of these three folders will be used. You can read more here: http://developer.android.com/guide/practices/screens_support.html

+2
source

You cannot create folders in res / drawable, the system does not recognize them.

+1
source

you need to save the image first and then make xml for them so that you can access it through R.your_pics

0
source
 context.getResources().getDrawable(R.drawable.progressbar1); 

Android - open resource from @drawable line

0
source

Source: https://habr.com/ru/post/898042/


All Articles