Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get Resources by name (string) and not by integer

for example:

public final class R {

    public static final class raw {
        public static final int yuri=0x7f040000;
    }
}

How can I get the resource by its name? Without using R.raw.yuri = (int)

like image 690
Alex Kapustian Avatar asked May 07 '10 09:05

Alex Kapustian


People also ask

How do you get string from resources?

android:text="@string/hello" /> String string = getString (R. string. hello); You can use either getString(int) or getText(int) to retrieve a string.

What is getResources() in android?

The Android resource system keeps track of all non-code assets associated with an application. You can use this class to access your application's resources. You can generally acquire the Resources instance associated with your application with getResources() .

In which folder can you find the string resource file strings XML?

You can find strings. xml file inside res folder under values as shown below.


1 Answers

getResources().getIdentifier( "yuri" , "raw" , getPackageName() );

I found this to be extremely slow. I stripped it out of my whole project after doing some profiling and used int[] instead.

like image 197
drawnonward Avatar answered Oct 11 '22 21:10

drawnonward