When trying to inflate and set my presenter to my databinding component in this way my presenter methods are not called.
val fragmentBinding = FragmentListEditBinding.inflate(layoutInflater)
fragmentBinding.presenter = ListEditorPresenter(this, requireContext())
but when using this
val fragmentBinding = DataBindingUtil.setContentView<FragmentListEditBinding(requireActivity(), R.layout.fragment_list_edit)
fragmentBinding.presenter = ListEditorPresenter(this, requireContext())
It works fine, but then the layout is covering the full screen. Any ideas how to fix this issue?
Please tell me if more context is needed.
The second method is for activity, not for the fragment, For fragment, you have to do it in the first method.
Before DataBinding and ViewBinding, In and
activity
we callsetContentView(R.layout.activity_main)
to set the view for theactivity
, but forfragment
, we override theonCreateView
method and inflate a view and return it.So the way of setting view for
activity
andfragment
is different from the beginning.So the
DataBindingUtil.setContentView
is made for activity, while theFragmentListEditBinding.inflate
custom/manual inflation is made for fragment. As i have already mentioned it above.