一
第一种方式是在组件的xml文件中配置android:onClick="click"
属性,然后在主类中添加click方法,
public void click(View view) {
System.out.println("hhh,我被点击了!!!");
Toast.makeText(this,"hhh,我被点击了!!!", Toast.LENGTH_SHORT).show();
}
下面的三种方式均先使用findViewById(R.id.button)方法先获得组件
//其中R.id.button为xml文件中button的id(android:id="@+id/button")
Button li_btn = findViewById