Reputation: 2053
I am trying to play sound OnItemClick
from a ListView
I have set up.
I'm getting the error "The method create(Context, int)
in the type MediaPlayer
is not applicable for the arguments (new AdapterView.OnItemClickListener(){}, int)
" with "create" underlined.
Not 100% sure why I am getting this error, if somebody could help, would be much appreciated.
ListView BoardList = (ListView) findViewById(R.id.BoardList);
BoardList.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
String List[] = {"Play 1", "Play 2", "Play 3", "Play 4", "Play 5", "Play 6", "Play 7", "Play 8", "Play 9" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.listcustomize, R.id.textItem, List);
BoardList.setAdapter(adapter);
BoardList.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (position == 0) {
MediaPlayer mPlayer = MediaPlayer.create(this, R.raw.Audio1);
mPlayer .start();
}
}
});
Upvotes: 1
Views: 303
Reputation: 2181
Instead of this
inside your MediaPlayer object you should write YourActivityName.this
and try again!
MediaPlayer mPlayer = MediaPlayer.create(YourActivityName.this, R.raw.Audio1);
This error occurs because you are inside the listener and the word this
refers to the listener itself and not to your Activity.
Upvotes: 5