How to use data-binding in Dialog?

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

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

Below is my xml.



    

        
8条回答
  •  -上瘾入骨i
    2021-01-30 12:55

    If you don't want to extend Dialog, another possible solution could be:

    Dialog dialog = new Dialog(this); // where "this" is the context
    
    YourClassNameBinding binding = DataBindingUtil.inflate(dialog.getLayoutInflater(), R.layout.your_layout, null, false);
    binding.setYourData(yourData);
    
    dialog.setContentView(binding.getRoot());
    dialog.show();
    
    

    Hope it helps.

提交回复
热议问题