Android和声音

时间:2012-03-26 12:04:45

标签: android audio

如何将mp3声音添加到android项目中,之后将它们添加到列表中?我添加了资产,但我不知道如何将它们添加到List 感谢

2 个答案:

答案 0 :(得分:2)

将它们放在资源文件夹中名为“raw”的子文件夹中。然后你可以将它们称为像图像或字符串那样的资源

答案 1 :(得分:0)

试试这个

Field[] fields=R.raw.class.getFields();
 int[] resourceID=new int[fields.length];
  String[] names=new String[fields.length];
for(int count=0; count < fields.length; count++){
    names[count]= fields[count].getName();<--- this is the list of names
     resourceID[count]=fields[count].getInt(fields[count]);<---- refer to those files using their ids in this array...(for example ..to play the audio.. u cannot get the file from name.. use this ids)
}

现在将数组传递给listview的适配器,如下所示

ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,R.layout.text,R.id.textView1, Arrays.asList(names););