How to use data-binding in Dialog?

前端 未结 8 1768
傲寒
傲寒 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:15

    You can do the same without calling getRoot().

    View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_delete_confirmation, null, false);
    
    mBinding = DialogDeleteConfirmationBinding.bind(view);
    
    mBinding.setViewModel(viewModel);
    
    builder.setView(view);
    
    builder.create();
    

提交回复
热议问题