Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在主布局上创建了一个按钮,然后在主活动中无法检测到它。请让我知道如何解决此问题。
注意:Android Studio 4.1.1.1 和 Kotlin
您无法直接访问该按钮。您需要将其附加到可以访问按钮的变量。
val newButton = findViewById<Button>(R.id.btnHelp); newButton.setOnClickListener(){ println(2+2) }
第一行创建一个变量并将其附加到按钮 ID。第二行连接点击监听器。