簡體   English   中英

這個 KOTLIN 代碼的 java 是什么?

[英]What is the java equivalent of this KOTLIN code?

我正在嘗試在 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) }
        }
    }

非常感謝

一般來說,它只是 null 檢查:

super.onViewCreated(view, savedInstanceState);
if (binding != null) {
    binding.orderOneCupcake.setOnClickListener(...);
    ...
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM