1 class MainActivity : AppCompatActivity() {
2
3 lateinit var tv:TextView; //初始化TextView 命名为tv
4 override fun onCreate(savedInstanceState: Bundle?) {
5 super.onCreate(savedInstanceState)
6 setContentView(R.layout.activity_main)
7
8 tv = findViewById(R.id.tv); 获取到TextView控件
9 tv.setOnClickListener { tv.setText("ABC") } 设置tv的点击事件
10 }
11 }