0
如何將mp3音頻添加到android項目中,然後將它們添加到列表中?我添加到資產,但我不知道如何將它們添加到列表中 謝謝Android和聲音
如何將mp3音頻添加到android項目中,然後將它們添加到列表中?我添加到資產,但我不知道如何將它們添加到列表中 謝謝Android和聲音
將它們放在資產文件夾中名爲'raw'的子文件夾中。然後,你可以稱他們爲像你這樣的資源將圖像或字符串
嘗試這樣
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););
怎麼辦你實際上是按名單的意思?一個ListView?你想在列表視圖中顯示文件嗎? – Rajkiran 2012-03-26 12:10:24
private List <>聲音; – edi233 2012-03-26 12:11:28