簡體   English   中英

無法在Android應用中的新View.OnFocusChangeListener()中使用MediaPlayer.create

[英]Can't use MediaPlayer.create in new View.OnFocusChangeListener() in Android app

好的,我遇到了我的Android應用程序中無法理解的問題。 在下面的代碼中,我在MediaPlayer mpWeight = MediaPlayer.create(this, R.raw.mppig)錯誤MediaPlayer mpWeight = MediaPlayer.create(this, R.raw.mppig) ;

將鼠標懸停在create上說:

MediaPlayer類型的方法create(Context, int)不適用於參數( 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();
                }
            }
      }          
    });

thisMediaPlayer.create(this, R.raw.mppig); 對應於OnFocusChangeListener的實例,但您需要傳遞應用程序上下文。

將您的創建呼叫更改為

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM