Android data binding is not working with attributes

前端 未结 2 1105
伪装坚强ぢ
伪装坚强ぢ 2020-12-09 02:49

I\'m trying to use databinding with custom views (a possible usage George Mount showed here).

One can\'t imagine building compound views without <

2条回答
  •  情歌与酒
    2020-12-09 03:25

    There is no merge object after inflation, so there is nothing to assign values to with a merge tag. I can't think of any binding tag that will work on merge.

    You can assign the tag to the root element and use the BindingAdapter to do what you want.

    
    
        
            
        
    
        
            
             
        
    
    

    If you want to do something with the Binding class itself, you can use the DataBindingUtil to find the object from the View.

    @BindingAdapter("isGone")
    public static void setGone(View view, boolean isGone) {
        ViewDataBinding binding = DataBindingUtil.findBinding(view);
        //... do what you want with the binding.
    }
    

提交回复
热议问题