【发布时间】:2022-01-18 20:23:49
【问题描述】:
我们看官方example:
private var _binding: ResultProfileBinding? = null
// This property is only valid between onCreateView and
// onDestroyView.
private val binding get() = _binding!!
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
_binding = ResultProfileBinding.inflate(inflater, container, false)
val view = binding.root
return view
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
为什么会有 2 个相似的变量:_binding 和 binding?为什么我们不能使用一个变量?
【问题讨论】:
-
@HenryTwist,是的,谢谢,好像是这样
标签: android kotlin android-viewbinding