发布时间:2020-04-22 20:55:41来源:阅读:
public class MainActivity extends Activity {
private Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
System.out.println("匿名内部类作为事件监听器");
}
});
}
}
public class MainActivity extends Activity {
private Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new ButtonOnClickListener());
}
class ButtonOnClickListener implements OnClickListener{
@Override
public void onClick(View v) {
System.out.println("内部类作为事件监听器");
}
}
}
public class MainActivity extends Activity implements OnClickListener{
private Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(this);
}
@Override
public void onClick(View v) {
System.out.println("Activity本身作为事件监听器");
}
}
public class MainActivity extends Activity {
private Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new ButtonOnClickListener());
}
}
class ButtonOnClickListener implements OnClickListener {
@Override
public void onClick(View v) {
System.out.println("外部类作为事件监听器");
}
}
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="点击事件"
android:onClick="onClick" />
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onClick(View v){
System.out.println("将事件处理方法直接绑定到标签");
}
}
2020-02-16
print spooler打印服务提示报错1608:依赖服务或组无法启动及Spoolsv.exe应用错误报错
如何关闭Windows 8的“快速启动”
zuihou-admin-cloud 1.6 发布,支持自动生成前端页面
如果《王者荣耀》中的女英雄长胖50斤,你觉得哪个依然美丽?
CoreOS Container Linux 宣布将结束生命周期
Portal3.x&Portal4.x&Portal5.x&Portal6.x私密文件柜帮助文档及常见问题
docker overlay网络实现
IdeaPad Y450/Y550/Y650系列机型桌面导航的使用
预装Win10家庭版的电脑提示激活到期的解决方案