RuntimeException:view标签在视图上不正确:ViewAgendaItemBinding.bind()方法上的null [英] RuntimeException: view tag isn't correct on view:null on ViewAgendaItemBinding.bind() method

查看:521
本文介绍了RuntimeException:view标签在视图上不正确:ViewAgendaItemBinding.bind()方法上的null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很简单的代码,应该根据几篇关于DataBinding的文章工作,但由于某些原因,它不是。



我正在尝试使用RecycleView和数据绑定。

  class ItemViewHolder extends RecyclerView.ViewHolder {

ViewAgendaItemBinding binding;

public ItemViewHolder(View itemView){
super(itemView);
binding = ViewAgendaItemBinding.bind(itemView); //这是它抛出错误的行。
}
}

我检查了这个 bind 方法,它看起来像这样:

  public static ViewAgendaItemBinding bind(android.view.View查看,android.databinding.DataBindingComponent bindingComponent){
if(!layout / view_agenda_item_0.equals(view.getTag())){
throw new RuntimeException(view tag is not correct on view :+ view.getTag());
}
返回新的ViewAgendaItemBinding(bindingComponent,view);
}

这是很奇怪的。因为我没有 layout / view_agenda_item_0 。这个视图应该使用 layout / view_agenda_item ,我显然不设置任何标签。但是,即使我为这个确切的元素设置了这些标签,它仍然不起作用。



我应该怎么解决这个问题?



PS但是,如果我将这个代码 ViewAgendaItemBinding.bind(itemView)更改为这个 DataBindingUtils.bind(itemView)它正在工作。数据绑定库中有问题吗?

解决方案

数据绑定在编译时重新编写布局文件,以便自动添加该标签



DataBindingUtils.bind 检查视图中是否存在现有绑定并重新使用它。看起来像其他地方,您已经在该视图上初始化了数据绑定。我想我们应该更改 ViewAgendaItemBinding.bind 方法来做同样的工作。


I have pretty simple code which should be working according several articles regarding DataBinding but for some reason it's not.

I'm trying to use RecycleView together with Databinding.

class ItemViewHolder extends RecyclerView.ViewHolder{

    ViewAgendaItemBinding binding;

    public ItemViewHolder(View itemView) {
        super(itemView);
        binding = ViewAgendaItemBinding.bind(itemView); //this is line where it's throw an error.
    }
}

I checked generated version of this bind method and it's looks like that:

public static ViewAgendaItemBinding bind(android.view.View view, android.databinding.DataBindingComponent bindingComponent) {
        if (!"layout/view_agenda_item_0".equals(view.getTag())) {
            throw new RuntimeException("view tag isn't correct on view:" + view.getTag());
        }
        return new ViewAgendaItemBinding(bindingComponent, view);
    }

Which is quite strange. Because I don't have layout/view_agenda_item_0. this view should use layout/view_agenda_item and I abviously not set any tags. However even if I set those tag for this exact element it's still isn't working.

What should I do to fix this?

P.S. However, If I change this code ViewAgendaItemBinding.bind(itemView) into this one DataBindingUtils.bind(itemView) it's working. Is it an issue in databinding library?

解决方案

Data binding re-writes your layouts files during compilation so it will add that tag automatically.

DataBindingUtils.bind checks if there is an existing binding on the view and re-uses it. Looks like somewhere else you've initialized data binding on that View. I think we should change ViewAgendaItemBinding.bind method to do the same as well.

这篇关于RuntimeException:view标签在视图上不正确:ViewAgendaItemBinding.bind()方法上的null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆