-1
我想存儲數組中的一些mp3文件的資源標識符。 這是代碼。Android:資源標識返回int值的ArrayList
private HashMap<String,List<Integer>> listHashMapnum;
private List<String> listhead;
listhead.add("Forty");
listhead.add("Fifty");
ArrayList<Integer> fortysound = new ArrayList<>();
fortysound.add(R.raw.forty);
ArrayList<Integer> fiftysound = new ArrayList<>();
fiftysound.add(R.raw.fifty);
然後我數組列表存儲在一個HashMap
listHashMapnum.put(listhead.get(0),fortysound);
listHashMapnum.put(listhead.get(1),fiftysound);
然後我用一個函數在HashMap中
public Integer getChild2(int i, int i1) {
return listHashMapnum.get(listheader.get(i)).get(i1);
}
我得到的功能等價值來獲取值這
Integer childsound = (Integer) getChild2(i, i1);
我的n使用childsound變量初始化媒體播放器
Button bt;
bt = (Button) view.findViewById(R.id.speaker);
final MediaPlayer mp = MediaPlayer.create(context, childsound);
bt.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view){
mp.start();
}
});
但該函數返回像一個int值「213736282」我發現了這一點,而試圖調試。 但我不明白爲什麼它這樣做,我可以做些什麼來從函數獲取我的資源標識符。 任何幫助是完全讚賞。 謝謝。
編輯: 錯誤實際上是在代碼的另一部分,所以上面的代碼是正確的。謝謝
請參閱讀取MP3 [**如何創建一個最小的,完整的,並且可驗證例如**](HTTPS: //stackoverflow.com/help/mcve) –
發佈這裏使用的所有變量的聲明,所以我們知道它們的類型。 – Neo
你確實得到它。是什麼讓你覺得有問題? – Oleg