【发布时间】:2017-02-14 21:01:36
【问题描述】:
尝试在 CustomView(Group) 中使用 DataBinding
布局如下:
<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">
<merge
android:layout_width="match_parent"
android:layout_height="match_parent">
<CheckBox
android:id="@+id/customview_checkbox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tag="@string/checkbox_value_key"
android:text="My CheckBox"/>
....
</merge>
</layout>
CustomView(扩展 FrameLayout)膨胀:
view = DataBindingUtil.inflate((LayoutInflater) getContext().getSystemService(Context
.LAYOUT_INFLATER_SERVICE), R.layout.custom_view, this, true);
导致此错误:
Error:(46, 61) error: cannot find symbol method getResources()
生成的绑定类:
public ViewBodyPartsBinding(android.databinding.DataBindingComponent bindingComponent, View[] root) {
super(bindingComponent, root[0], 0);
final Object[] bindings = mapBindings(bindingComponent, root, 9, sIncludes, sViewsWithIds);
this.mboundView0 = (android.widget.ImageView) bindings[0];
this.mboundView0.setTag(null);
this.mboundView2 = (android.support.percent.PercentRelativeLayout) bindings[2];
this.mboundView2.setTag(null);
....
this.customviewCheckbox1 = (android.widget.CheckBox) bindings[1];
this.customviewCheckbox1.setTag(root.getResources().getString(<package>.R.string.checkbox_value_key));
....
setRootTag(root);
// listeners
invalidateAll();
}
【问题讨论】:
-
我没有在
元素上设置标签。因此它应该工作恕我直言 -
这似乎是您用于 CheckBox 的标签属性的问题。在尝试自己并搜索后,我想出了这个stackoverflow.com/questions/31826201/…
-
George Mount 回复您
or supply a fixed tag or resource string。我正在使用一个资源字符串,这就是为什么我认为它应该可以工作。 -
您是否尝试删除标记属性。你可以自己检查一下
-
这个错误看起来仍然存在。在它为 Android Studio 2.3 修复之前,您可以使用硬编码字符串来解决它。对不起!
标签: android data-binding android-databinding