1、布局文件中声明控件
<TextView android:id="@+id/first_test" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" />
2、设置点击事件
3、实现接口方法
first_test.setOnClickListener(object : View.OnClickListener{ override fun onClick(p0: View?) { TODO("not implemented") //To change body of created functions use File | Settings | File Templates. } })
4、转lambda
5、重写实现方法
first_test.setOnClickListener { //TODO("not implemented") //To change body of created functions use File | Settings | File Templates. Log.d(TAG,"click --- ") }
6、运行结果: