我怎样才能获得的资源按名称(字符串),而不是整数整数、字符串、而不是、名称

2023-09-13 01:03:53 作者:静待另一片天

例如:

 公共final类环R {

    公共静态final类原料{
        公共静态最终诠释尤里= 0x7f040000;
    }
}
 

我怎样才能获得其名称的资源? 如果不使用R.raw.yuri =(INT)

解决方案

  getResources()则getIdentifier(尤里,原始,getPackageName())。
 
注册表中性能计数器名称字符串数值的格式不正确

我发现这是非常缓慢的。我剥离出来我的整个项目做一些分析后,并使用 INT [] 代替。

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)

解决方案

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.