OstAlex OstAlex - 25 days ago 10
Android Question

Android DataBinding —— view tag isn't correct on view:null

My class extend the LinearLayout, I use DataBinding to inflate the layout.But the code throws an exception that it is view tag isn't correct on view:null .

this is my code :

public class DietListView extends LinearLayout {
private LayoutDietListViewBinding mBinding;
private List<?> mDietList = new LinkedList<>();
private LayoutInflater mInflater;

public DietListView(Context context) {
this(context,null);
}

public DietListView(Context context, AttributeSet attrs) {
this(context, attrs,0);
}

public DietListView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initView(context);
}

private void initView(Context context) {
mInflater = LayoutInflater.from(context);
mBinding = DataBindingUtil.inflate(mInflater, R.layout.layout_diet_list_view, null, false);
addView(mBinding.getRoot());

}


}

The Layout file is:

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
xmlns:bind="http://schemas.android.com/apk/res-auto">
<data>

</data>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">

.....

</LinearLayout>
</layout>

Answer

There is a bug related to this. When you do data binding during inflation, it is confusing the data binding framework. Try delaying your inflation until after the data binding framework completes to see if it will work. The bug should be fixed in android gradle plugin 2.2 (Android Studio 2.2), but won't be available in the I/O 2016 preview.

https://code.google.com/p/android/issues/detail?id=204890

Comments