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>