在 setOnClickListener (Kotlin) 中,{ it } 和 { view: View -> view... } 有什么区别?
in setOnClickListeners (Kotlin), what is the different between { it } and { view: View -> view... }?
在 setOnClickListeners (Kotlin) 中,{ it } 和 { view: View -> view... } 有什么区别?
我都试过了,都有效。所以我想知道有什么不同?如果我一直使用 {it} 可以吗?因为它更容易记住。
-> 符号有什么用?
binding.playButton.setOnClickListener { view: View ->
view.findNavController().navigate(R.id.action_titleFragment_to_gameFragment)
}
binding.playButton.setOnClickListener {
it.findNavController().navigate(R.id.action_titleFragment_to_gameFragment)
}
提前致谢:)
当 lambda 只有一个参数时,它默认公开为 it
。您可以选择使用以下语法为其指定一个显式名称:{ name -> }
.
在 setOnClickListeners (Kotlin) 中,{ it } 和 { view: View -> view... } 有什么区别?
我都试过了,都有效。所以我想知道有什么不同?如果我一直使用 {it} 可以吗?因为它更容易记住。
-> 符号有什么用?
binding.playButton.setOnClickListener { view: View ->
view.findNavController().navigate(R.id.action_titleFragment_to_gameFragment)
}
binding.playButton.setOnClickListener {
it.findNavController().navigate(R.id.action_titleFragment_to_gameFragment)
}
提前致谢:)
当 lambda 只有一个参数时,它默认公开为 it
。您可以选择使用以下语法为其指定一个显式名称:{ name -> }
.