LokiDroid LokiDroid - 1 year ago 78
Android Question

android - images in Drawable folder and getting their id's into java

I'm new to development and I'm stuck at a point where I don't know what would be the best possible solution.

I have a list of 26 images saved in the drawable folder. Lets say a to z. When user clicks on the right side layout they should navigate forward and if the user clicks on the left side layout they should navigate backwards.

My issue is that these are images and their IDs as retrieved by android are random int values. I can't use that to compare which letter of alphabet should be displayed next.

How do I go about this problem?

  1. If I name the images a.png, b.png, c.png... How do I retrieve the name later from the ID?

  2. Will I be able to store the drawables as a key value pair using collection framework?

Answer Source

You can get the name of your resource by

String resourceName = getResources().getResourceName(resId);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download