是否可以不使用特定的resid名称?android编程

是否可以不使用特定的resid名称?android编程,android,Android,是否可以不使用特定的resid名称 例如,我认为正常的方式是这样的: MediaPlayer sound = MediaPlayer.create(main.this, R.raw.abandon); //abandon being the soundfile file name inside the raw folder String string= abandon; MediaPlayer sound = MediaPlayer.create(main.this,

是否可以不使用特定的resid名称

例如,我认为正常的方式是这样的:

    MediaPlayer sound = MediaPlayer.create(main.this, R.raw.abandon);  //abandon being the soundfile file name inside the raw folder
    String string= abandon;
    MediaPlayer sound = MediaPlayer.create(main.this, R.raw.string); 
这是可能的,或是他们的一种方式,使这样:

    MediaPlayer sound = MediaPlayer.create(main.this, R.raw.abandon);  //abandon being the soundfile file name inside the raw folder
    String string= abandon;
    MediaPlayer sound = MediaPlayer.create(main.this, R.raw.string); 
我想上面的方法,因为im使用输入字符串播放原始文件夹上的文件
如果有点混乱,很抱歉..但我真的需要帮助。tnx

您要做的是将其存储为整数

int id= R.raw.abandon;
MediaPlayer sound = MediaPlayer.create(main.this, id); 
R.raw.about
返回资源的id标识符。在create方法中使用


您可以将此int存储到任何名称的变量中,然后将其传递。

这个问题有点让人困惑。你的意思是你想用任何名字来代替放弃?