我正在Android应用程序中创建我的第一个Kotlin类。通常,出于日志记录的目的,我有一个名为TAG的常量。我在Java中要做的是: private static final String TAG = MyClass.class.getSimpleName(); 我知道在Kotlin类中,我可以使用以下方式创建TAG: private val TAG = My
我知道这可能是一个很简单的问题,但我想从activity导入我的按钮 _ id为“button1”的main.xml: In the MainActivity.kt so I can add a setOnClickListenerWhats the standard way of importing a button with kotlin so I can use it properly?
通常我们不会在kotlin中使用findViewById (R.id.listView),因为Android会自动为我们做这件事(我们不需要找到视图)。但是示例显示我们需要它(在这一行代码中):
val listView = findViewById<ListView>(R.id.listView) as ListView.