Presenter is not called in onClick

73 Views Asked by At

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.

1

There are 1 best solutions below

0
On

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 call setContentView(R.layout.activity_main) to set the view for the activity, but for fragment, we override the onCreateView method and inflate a view and return it.

So the way of setting view for activity and fragment is different from the beginning.

So the DataBindingUtil.setContentView is made for activity, while the FragmentListEditBinding.inflate custom/manual inflation is made for fragment. As i have already mentioned it above.