I have an array like this.
int image[] = {R.drawable.d002_p001,R.drawable.d002_p002,R.drawable.d002_p003, R.drawable.d002_p004,R.drawable.d002_p005,R.drawable.d002_p006};
Right now I have 6 images so I am statically given the name.
If I have some 50 images I cant give each and every file name in array so it needs to be dynamic how can I achieve this.
Then you can see the drawable folder under app —> res folder in the panel below the subview. Copy images from any directory you saved and right-click the drawable folder, click the Paste menu item in the popup menu list then accept all popup dialog. After that, you can see the images added in the drawable folder.
Go to the solution explorer, select Resource--> drawable. Right click --> add--> Existing Item. or (Shift + Alt + A).
You can use getIdentifier()
for (int j = 1; j < 6; j++) { Drawable drawable = getResources().getDrawable(getResources() .getIdentifier("d002_p00"+j, "drawable", getPackageName())); }
You can also use this:
int res = getResources().getIdentifier("<your pakecgename>:drawable/abc", null, null);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With