我正在尝试在我的项目中使用新的Android数据绑定,但是当我尝试将“android:tag”属性设置为某些自定义变量时,我遇到了错误。
我的menu_item.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="menuItem"
type="com.example.MenuItem" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:tag="@{menuItem}"
tools:ignore="UseCompoundDrawables">
<!--suppress AndroidUnknownAttribute -->
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:imageResource="@{menuItem.itemType.drawableId}" />
<TextView
android:id="@+id/displayName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{menuItem.itemType.displayNameId}" />
</LinearLayout>
</layout>
我的 MenuItem 类:
public class MenuItem {
public final ItemType itemType;
public MenuItem(ItemType itemType) {
this.itemType = itemType;
}
}
生成的MenyItemBinding.java部分代码:
public MenuItemBinding(View root) {
super(root, 0);
final Object[] bindings = mapBindings(root, 3, sIncludes, sViewsWithIds);
this.displayName = (android.widget.TextView) bindings[2];
this.displayName.setTag(null);
this.icon = (android.widget.ImageView) bindings[1];
this.icon.setTag(null);
this.mboundView0 = (android.widget.LinearLayout) bindings[0];
this.mboundView0.setTag(root.getResources().getString(com.myApp.R.string.@{menuItem}));
setRootTag(root);
invalidateAll();
}
错误出现在生成的类中,当尝试设置绑定视图的标记时。
有什么想法可以解决这个问题吗?最好不要使用自定义LinearLayout来支持此功能。