본문 바로가기

Android

Accessing Android Resources By Name at Runtime


For example: I have a file bug.png in the "/res/drawable/ ", so i get its ResourceID with the following code:

int resID = getResources( ) .getIdentifier ( "org.anddev.android.testproject:drawable/bug" , null , null ) ;
// or
int resID = getResources( ) .getIdentifier ( "bug" , "drawable" , "org.anddev.android.testproject" ) ;