我创建了一个ListView,每个ListView项都有2个TextView,一个图像和一个音频文件。一切正常,并且播放了音频文件,但是当我多次单击项目并上下滚动时,不会播放音频文件。那部分有什么问题?
这是我的Java代码:
public class NumbersActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_numbers);
ArrayList<Word> words = new ArrayList<>();
words.add(new Word("one","un",R.drawable.number_one,R.raw.one));
words.add(new Word("two","deux",R.drawable.number_two,R.raw.two));
.......
ListView listView = (ListView) findViewById(R.id.numberViewlist);
WordAdapter itemsAdapter = new WordAdapter(this,
words,R.color.category_numbers,listView);
listView.setAdapter(itemsAdapter);
}
}
这是WordAdaper的代码:
lView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
MediaPlayer mp = MediaPlayer.create(getContext(),currentWord.getsound());
mp.start();
}
});
答案 0 :(得分:0)