0

好的,我在我的 Android 应用程序中遇到了一个我不明白的问题。在下面的代码中,我在MediaPlayer mpWeight = MediaPlayer.create(this, R.raw.mppig);

将光标悬停在 create 上说:

create(Context, int)类型中的方法MediaPlayer不适用于参数 ( new View.OnFocusChangeListener(){}, int)

这是什么意思,更重要的是,我该如何解决?

这是整个例程:

    TextView tv=(TextView)findViewById(R.id.weight);
    tv.setOnFocusChangeListener(new OnFocusChangeListener(){
      @Override
      public void onFocusChange(View v,boolean hasFocus){
            /* When focus is lost check that the text field
             * has valid values.
             */
            if (!hasFocus) {
                float tempweight = Float.parseFloat(et_weight.getText().toString());
                if(tempweight > 200){
                    MediaPlayer mpWeight = MediaPlayer.create(this, R.raw.mppig);
                    mpWeight.start();
                }
            }
      }          
    });
4

1 回答 1

0

thisMediaPlayer.create(this, R.raw.mppig);对应的实例,OnFocusChangeListener但您需要传递应用程序上下文。

将您的创建调用更改为

MediaPlayer.Create(getApplicationContext(), R.raw.mppig);

于 2011-08-08T13:52:06.817 回答