android 的The method makeText(Context, CharSequence, int) in the type Toast is not applicable fo(

學習android的時碰到的一個問題:

 

具體代碼如下:

public class HelloformstufActivity extends Activity {
 private Button mButton;
 private RatingBar  mRating;
   
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mButton = (Button)findViewById(R.id.button1);
        mRating = (RatingBar)findViewById(R.id.ratingBar1);
        mButton.setOnClickListener(new View.OnClickListener() {
   
   @Override
   public void onClick(View v) {
    Toast.makeText(this, "beep", Toast.LENGTH_SHORT).show();
   }
  });

       
    }
}

總是出現The method makeText(Context, CharSequence, int) in the type Toast is not applicable for the
 arguments (new View.OnClickListener(){}, String, int)

修改成

Toast.makeText(HelloformstufActivity.this, "beep", Toast.LENGTH_SHORT).show();

 

this和HelloformstufActivity.this不同嗎?不同在哪啊?

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章