1

我正在尝试播放我设置的OnItemClick声音。ListView

我收到错误“create(Context, int)类型MediaPlayer中的方法不适用于参数(new AdapterView.OnItemClickListener(){}, int)”,“create”下划线。

不是 100% 确定我为什么会收到此错误,如果有人可以提供帮助,将不胜感激。

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();
            }
        }
    });
4

1 回答 1

5

而不是this在您的 MediaPlayer 对象中,您应该编写并重YourActivityName.this试!

MediaPlayer  mPlayer = MediaPlayer.create(YourActivityName.this, R.raw.Audio1);

发生此错误是因为您在侦听器内部,并且该词this指的是侦听器本身而不是您的 Activity。

于 2013-08-21T14:05:07.667 回答