我正在使用包含一些图像的网格视图。我想在单击 gridview 中的每个图像时添加声音效果。我在 res/raw 文件夹中添加了图像并添加了以下代码。
MediaPlayer mp;
gridView.setAdapter(new ImageAdapter(this));
gridView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView parent, View v,int position,long id) {
if (position == 0) {
mp = MediaPlayer.create(this, R.raw.ok);
Toast.makeText(getBaseContext(),
"Shape Matched",
Toast.LENGTH_LONG).show();
startActivity(new Intent("com.example.TestShapeActivity2"));
} else {
mp = MediaPlayer.create(this, R.raw.no);
Toast.makeText(getBaseContext(),
"Please Try Again",
Toast.LENGTH_LONG).show();
//startActivity(new Intent("com.example.TestShapeActivity2"));
}
}
});
但是创建函数给出了错误
The method create(Context, int) in the type MediaPlayer is not applicable for the arguments (new AdapterView.OnItemClickListener(){}, int).
请帮助我。谢谢。