![](/img/trans.png)
[英]The inflate method for my binding is not found (using Android, Data Binding.)
[英]Android Data Binding. Button onClick not working
我卡在這里了,求助。
我有以下代碼:
簡介片段:
@AndroidEntryPoint
class ProfileFragment : Fragment() {
private val profileViewModel: ProfileViewModel by viewModels()
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val binding = FragmentProfileBinding.inflate(inflater, container, false)
binding.viewModel = profileViewModel
binding.lifecycleOwner = viewLifecycleOwner
return binding.root
}
}
我不確定這個問題是否仍然存在,但如果您使用數據綁定和 hilt 進行依賴注入,請在您的片段 onViewCreated 中添加以下幾行
binding.lifecycleOwner = this
binding.viewModel = profileViewModel
為我解決這個問題的方法是在onCreateView<\/em>中添加對自身的片段引用:
binding.<fragment_name> = this
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.