public static int getId ( Context context , String id , String defType ) { String type = "R." + defType + "." ; if ( id . startsWith ( type ) ) { id = id . substring ( type . length ( ) ) ; } Resources r = context . getResources ( ) ; int resId = r . getIdentifier ( id , defType , context . getPackageName ( ) ) ; if ( resId > 0 ) { return resId ; } else { throw new RuntimeAssertion ( "Specified resource '%s' could not be found" , id ) ; } }
Get the int resource id with specified type definition