-1

Trying to use WordAdapter.this as a Context doesn't get accepted by the compiler in the following code:

playButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                MediaPlayer mp = MediaPlayer.create(WordAdapter.this, currentWord.getAudioResourceId());
                mp.start();
            }
        });

The class is WordAdapter, and it extends ArrayAdapter using a collection of Word objects.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
mr.uaila
  • 3
  • 5

1 Answers1

0

MediaPlayer.create() needs a Context as first parameter. You can pass an context to it. Your adapter class is not child of Context class so you can not pass WordAdapter.this as an context.

Khemraj Sharma
  • 57,232
  • 27
  • 203
  • 212