RuntimeException: view tag isn't correct on view:null on ViewAgendaItemBinding.bind() method

半世苍凉 提交于 2019-12-23 14:21:39

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/37883771/runtimeexception-view-tag-isnt-correct-on-viewnull-on-viewagendaitembinding-b

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!