How to use data-binding in Dialog?

前端 未结 8 1765
傲寒
傲寒 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:20
      mBinding = DataBindingUtil.inflate(LayoutInflater.from(getContext()), R.layout.dialog_select, null, false);
        setContentView(mBinding.getRoot());
        SelectDialogBean data = new SelectDialogBean();
        mBinding.setData(data);
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题