2012-03-26 165 views
0

如何将mp3音频添加到android项目中,然后将它们添加到列表中?我添加到资产,但我不知道如何将它们添加到列表中 谢谢Android和声音

+0

怎么办你实际上是按名单的意思?一个ListView?你想在列表视图中显示文件吗? – Rajkiran 2012-03-26 12:10:24

+0

private List <>声音; – edi233 2012-03-26 12:11:28

回答

2

将它们放在资产文件夹中名为'raw'的子文件夹中。然后,你可以称他们为像你这样的资源将图像或字符串

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););