我在listenview中重現聲音。我有一個自定義的適配器,但它總是失敗,我把int與MP3的資源! ono肯定我perdnto的東西,但不知道什麼!如何解決的建議?謝謝listview中的媒體播放器
public class Adapter_animal extends ArrayAdapter<String> {
private final Activity context;
private final String[] animal;
private final int[] animal_id;
private MediaPlayer mp;
public Adapter_animal(Activity context, int mylist, String[] animal, int[] animal_id) {
super(context, R.layout.mylist, animal);
// TODO Auto-generated constructor stub
this.context=context;
this.animal = animal;
this.animal_id = animal_id;
}
public View getView(final int position,View view,ViewGroup parent) {
LayoutInflater inflater=context.getLayoutInflater();
View rowView=inflater.inflate(R.layout.mylist, null,true);
TextView txtTitle = (TextView) rowView.findViewById(R.id.titolo);
txtTitle.setText(animal[position]);
FloatingActionButton btn = (FloatingActionButton) rowView.findViewById(R.id.f1_btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
stopPlaying();
mp = MediaPlayer.create(Adapter_animal.this, animal_id); //error in this line "cannot resolve method
mp.start();
}
});
return rowView;
};
private void stopPlaying() {
if (mp != null) {
mp.stop();
mp.release();
mp = null;
}
}
串
static String[] animal={
"animale",
"animale2",
"animale3",
};
static int[] animal_id={
R.raw.a11_ovation,
};
什麼我會改變一個
MediaPlayer
對象,或者爲null -)的資源作爲數據源使用返回
MediaPlayer
?對不起,但我不是專家,我想弄清楚如何解決! – gilione使用數組中的索引器傳遞所需的資源ID。即:animal_id [0] –