How to use data-binding in Dialog?

前端 未结 8 1773
傲寒
傲寒 2021-01-30 12:29

I am having trouble in implementing databinding in a Dialog. Is it possible?

Below is my xml.



    

        
8条回答
  •  情话喂你
    2021-01-30 13:21

    It is possible to use databinding in a Dialog, first to get the binding working on your Dialog you should inflate it first and pass it to the setContentView like this.

    DialogOlaBookingConfirmedBinding binding = DataBindingUtil.inflate(LayoutInflater.from(getContext()), R.layout. dialog_ola_booking_confirmed, null, false);
    setContentView(binding.getRoot());
    

    Then you can pass the viewModel:

    binding.setViewModel(new ViewModel(this, event.olaBooking));
    

    And now you can see it working.

提交回复
热议问题