在过去的一天中,我没有找到任何显示如何执行此操作的内容,我所看到的所有内容都带有一个基本按钮,我无法复制该按钮以与图像按钮一起使用。使用 setOnClickListener 似乎根本不起作用,尽管我发现使用它们的唯一案例已经有 5 年多了。
Android Studio 中是否有相当于链接活动的 Storyboard?
这是我发现的一个 7 年前的例子。
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val myButton =
findViewById<View>(R.id.live) as ImageButton
myButton.setOnClickListener(object : OnClickListener() {
// When the button is pressed/clicked, it will run the code below
fun onClick() {
// Intent is what you use to start another activity
val intent = Intent(this, LiveActivity::class.java)
startActivity(intent)
}
})
}
}
Run Code Online (Sandbox Code Playgroud)
给出以下错误:
Object is not abstract and does not implement abstract member …Run Code Online (Sandbox Code Playgroud)