Java 使用字符串引用原始文件夹中的文件

Java 使用字符串引用原始文件夹中的文件,java,android,reference,mp3,Java,Android,Reference,Mp3,我正在寻找一种解决方案,如何通过字符串引用原始文件夹中的.mp3文件 确切地说,我希望遍历所有名为player1.mp3、player2.mp3等的原始文件,并将资源id存储在int数组中,该数组应按正确的播放器顺序包含id 我的想法是这样的: int[] playerArray = new int[100]; String filename; for(int i = 0; i<100; i++){ filename = "player"+String.valueOf(i);

我正在寻找一种解决方案,如何通过字符串引用原始文件夹中的.mp3文件

确切地说,我希望遍历所有名为
player1.mp3、player2.mp3等的原始文件,并将资源id存储在int数组中,该数组应按正确的播放器顺序包含id

我的想法是这样的:

int[] playerArray = new int[100];
String filename;
for(int i = 0; i<100; i++){
   filename = "player"+String.valueOf(i);
   playerArray = R.raw.filename; //I know, this does not work
}
int[]playerary=newint[100];
字符串文件名;

对于(int i=0;i您可以使用以下代码:

int rawId = context.getResources().getIdentifier(filename, "raw", context.getPackageName());
使用getResources()方法可以获取所有ressource的id。第二个参数是ressource的类型(string、drawable、raw等)

您的代码如下所示:

int[] playerArray = new int[100];
String filename;
for(int i = 0; i<100; i++){
   filename = "player"+String.valueOf(i);
   int rawId = context.getResources().getIdentifier(filename, "raw", context.getPackageName());
   playerArray[i] = rawId;
}
int[]playerary=newint[100];
字符串文件名;

对于(int i=0;i您可以使用以下代码:

int rawId = context.getResources().getIdentifier(filename, "raw", context.getPackageName());
使用getResources()方法可以获取所有ressource的id。第二个参数是ressource的类型(string、drawable、raw等)

您的代码如下所示:

int[] playerArray = new int[100];
String filename;
for(int i = 0; i<100; i++){
   filename = "player"+String.valueOf(i);
   int rawId = context.getResources().getIdentifier(filename, "raw", context.getPackageName());
   playerArray[i] = rawId;
}
int[]playerary=newint[100];
字符串文件名;

对于(int i=0;i您可以使用以下代码:

int rawId = context.getResources().getIdentifier(filename, "raw", context.getPackageName());
使用getResources()方法可以获取所有ressource的id。第二个参数是ressource的类型(string、drawable、raw等)

您的代码如下所示:

int[] playerArray = new int[100];
String filename;
for(int i = 0; i<100; i++){
   filename = "player"+String.valueOf(i);
   int rawId = context.getResources().getIdentifier(filename, "raw", context.getPackageName());
   playerArray[i] = rawId;
}
int[]playerary=newint[100];
字符串文件名;

对于(int i=0;i您可以使用以下代码:

int rawId = context.getResources().getIdentifier(filename, "raw", context.getPackageName());
使用getResources()方法可以获取所有ressource的id。第二个参数是ressource的类型(string、drawable、raw等)

您的代码如下所示:

int[] playerArray = new int[100];
String filename;
for(int i = 0; i<100; i++){
   filename = "player"+String.valueOf(i);
   int rawId = context.getResources().getIdentifier(filename, "raw", context.getPackageName());
   playerArray[i] = rawId;
}
int[]playerary=newint[100];
字符串文件名;

对于(int i=0;我不使用res/raw文件夹而使用资产文件夹,AssetManager不使用res/raw文件夹而使用资产文件夹,AssetManager不使用res/raw文件夹而使用资产文件夹,AssetManager不使用res/raw文件夹而使用资产文件夹和AssetManager银行,这正是我要找的:)谢谢,那正是我想要的:)谢谢,那正是我想要的:)谢谢,那正是我想要的:)