学习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不同吗?不同在哪啊?