Kotlin中匿名内部类,引用Activity的this用法为 this@MainActivity (对应自己的Activity)
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
test.setOnClickListener{
Toast.makeText(this@MainActivity,"测试匿名类引用外部类",Toast.LENGTH_LONG).show()
}
}