好的,我的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();
}
}
}
});
答案 0 :(得分:0)
this
中的MediaPlayer.create(this, R.raw.mppig);
对应OnFocusChangeListener
的实例,但您需要传递应用程序上下文。
将您的创建调用更改为
MediaPlayer.Create(getApplicationContext(), R.raw.mppig);