我在listeview中再现声音。我有一个自定义的适配器,但它总是在我将int与mp3的资源放在一起的那一行失败!我不确定我听到了什么,但不知道是什么!如何解决的建议?非常感谢。
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,
};