[TinyTut] - Get Resources by Name ( getIdentifier(...); )
What you learn: You will learn how get Resource-IDs by their name, using the getResources().getIdentifier(...); Method
Possible Scenario: You have a sequence of resource-images with almost the same name and want to get the IDs of all of them.
Difficulty: 1 of 5

Description:
For example: I have a file bug.png in the "/res/drawable/", so i get its ResourceID with the following code:
Using java Syntax Highlighting
- int resID = getResources().getIdentifier("org.anddev.android.testproject:drawable/bug", null, null);
- // or
- int resID = getResources().getIdentifier("bug", "drawable", "org.anddev.android.testproject");
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
[hr]
[hr]
The function we are using in general:
Using java Syntax Highlighting
- public int getIdentifier(String name, String defType, String defPackage)
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
It can be used in two ways (depends on which way you prefer) as you can see above:
1. "name" can be the 'full path' to the resource, built up like this (the params defType and defPackage remain null)
Using java Syntax Highlighting
- full_package:type/filename_without_ending
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
2. Split up filename, type and package
Thats it 

Regards,
plusminus





