android 触发器

学android 第一天

添加Toast

 Button button1=(Button)findViewById(R.id.button_1);
        button1.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
Toast.makeText(HelloWordActivity.this, "You clicked Button 1",Toast.LENGTH_SHORT).show();
}
});

这段代码一直报错

The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the argument.

导入文件 import android.view.View.OnClickListener; 就可以了


猜你喜欢

转载自blog.csdn.net/Cholexuti/article/details/78311245