How to use data-binding with Fragment

后端 未结 14 1032
不思量自难忘°
不思量自难忘° 2020-11-29 16:48

I\'m trying to follow data-binding example from official google doc https://developer.android.com/tools/data-binding/guide.html

except that I\'m trying to apply data

14条回答
  •  -上瘾入骨i
    2020-11-29 17:23

    If you are using ViewModel and LiveData This is the sufficient syntax

    Kotlin Syntax:

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return MartianDataBinding.inflate(
            inflater,
            container,
            false
        ).apply {
            lifecycleOwner = viewLifecycleOwner
            vm = viewModel    // Attach your view model here
        }.root
    }
    

提交回复
热议问题