Search code examples
androidresource-id

How to get id of the resource of the specified name?


I have files in the folder drawable which are named in one way:

v[versionNumber]i[nameOfFile] 

Example: v1i2

And in the activity code I have a

String fileName = "v1i2;//name of the desired resource id
int drawableId = GETTHISID(fileName);

Is it possible to get id of this drawableId resource?


Solution

  • Try:

    for (int i=0;i<10;i++){
        int id = getResources().getIdentifier("v"+i+"i"+i,"drawable", getPackageName()); 
    }