[英]What is the java equivalent of this KOTLIN code?
I'm trying to do a google codelabs project on data binding in java to help me learn kotlin. This is the code, I am having trouble structuring the onViewCreated method with data binding我正在尝试在 java 中做一个关于数据绑定的谷歌代码实验室项目,以帮助我学习 kotlin。这是代码,我在使用数据绑定构建 onViewCreated 方法时遇到问题
...
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding?.apply {
orderOneCupcake.setOnClickListener { orderCupcake(1) }
orderSixCupcakes.setOnClickListener { orderCupcake(6) }
orderTwelveCupcakes.setOnClickListener { orderCupcake(12) }
}
}
Many thanks非常感谢
it will be just null check in general:一般来说,它只是 null 检查:
super.onViewCreated(view, savedInstanceState);
if (binding != null) {
binding.orderOneCupcake.setOnClickListener(...);
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.