Compilation error: Cannot find symbol FragmentBindingImpl with custom attributes
Compilation error: Cannot find symbol FragmentBindingImpl with custom attributes
我在其他地方有数据绑定,这是唯一给我这些问题的地方我没有匕首。如果我删除此视图中使用数据绑定的行,我不会收到任何错误,并且可以在我的设备上安装。我已经尝试了 rebuilding/restarting 和清除缓存以及删除构建文件的所有组合。我也试过禁用数据绑定并重新启用它。
这是我正在使用的布局文件 fragment_subscription.xml
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable name="fragment" type="com.example.subscription.SubscriptionFragment"/>
<variable name="week" type="com.android.billingclient.api.SkuDetails"/>
<variable name="month" type="com.android.billingclient.api.SkuDetails"/>
<variable name="year" type="com.android.billingclient.api.SkuDetails"/>
</data>
<com.example.CustomButton
android:id="@+id/week_subscription_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:padding="5dp"
app:presetButtonPriceText="@{week.price}"
app:presetButtonUnitText="@string/week_subscription_unit"
app:presetButtonValueText="@string/week_subscription_value"/>
<com.example.CustomButton
android:id="@+id/month_subscription_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:padding="5dp"
app:presetButtonPriceText="@{month.price}"
app:presetButtonUnitText="@string/month_subscription_unit"
app:presetButtonValueText="@string/month_subscription_value"/>
<com.example.CustomButton
android:id="@+id/year_subscription_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:padding="5dp"
app:presetButtonPriceText="@{year.price}"
app:presetButtonUnitText="@string/year_subscription_unit"
app:presetButtonValueText="@string/year_subscription_value"/>
</layout>
这是我的自定义按钮特定视图属性
<attr name="presetButtonUnitText" format="integer"/>
<attr name="presetButtonPriceText" format="string"/>
<attr name="presetButtonValueText" format="integer"/>
这是我在 SubscriptionFragment.kt
中创建视图的地方
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return FragmentSubscriptionBinding.inflate(inflater, container, false).let {
this.binding = it
bind(skuDetailsList)
it.root
}
}
这是我绑定视图的地方
private fun bind(skuList: MutableList<SkuDetails>) {
binding?.let {
if (skuList.isNotEmpty()) {
it.week = skuList[0]
it.month = skuList[1]
it.year = skuList[2]
it.fragment = SubscriptionFragment@this
}
}
}
我尝试在我的应用程序中添加这些行 gradle.properties
android.databinding.enableV2 = true
android.enableExperimentalFeatureDatabinding = true
我已将这些添加到我的应用程序中 gradle
kapt 'com.android.databinding:compiler:3.1.4'
kapt {
generateStubs = true
}
configurations.all {
resolutionStrategy {
force 'com.android.support:support-annotations:23.1.1'
}
}
这里我绑定了自定义属性,需要在我膨胀的自定义视图中设置自定义 getters/setters
编辑:
例子
public class ColorPicker extends View {
private int color;
public void setColor(int color) {
this.color = color;
invalidate();
}
public int getColor() {
return color;
}
//...
}
这是 xml 的样子
<com.example.myapp.ColorPicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:color="@{color}"/>
我在其他地方有数据绑定,这是唯一给我这些问题的地方我没有匕首。如果我删除此视图中使用数据绑定的行,我不会收到任何错误,并且可以在我的设备上安装。我已经尝试了 rebuilding/restarting 和清除缓存以及删除构建文件的所有组合。我也试过禁用数据绑定并重新启用它。
这是我正在使用的布局文件 fragment_subscription.xml
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable name="fragment" type="com.example.subscription.SubscriptionFragment"/>
<variable name="week" type="com.android.billingclient.api.SkuDetails"/>
<variable name="month" type="com.android.billingclient.api.SkuDetails"/>
<variable name="year" type="com.android.billingclient.api.SkuDetails"/>
</data>
<com.example.CustomButton
android:id="@+id/week_subscription_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:padding="5dp"
app:presetButtonPriceText="@{week.price}"
app:presetButtonUnitText="@string/week_subscription_unit"
app:presetButtonValueText="@string/week_subscription_value"/>
<com.example.CustomButton
android:id="@+id/month_subscription_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:padding="5dp"
app:presetButtonPriceText="@{month.price}"
app:presetButtonUnitText="@string/month_subscription_unit"
app:presetButtonValueText="@string/month_subscription_value"/>
<com.example.CustomButton
android:id="@+id/year_subscription_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical"
android:padding="5dp"
app:presetButtonPriceText="@{year.price}"
app:presetButtonUnitText="@string/year_subscription_unit"
app:presetButtonValueText="@string/year_subscription_value"/>
</layout>
这是我的自定义按钮特定视图属性
<attr name="presetButtonUnitText" format="integer"/>
<attr name="presetButtonPriceText" format="string"/>
<attr name="presetButtonValueText" format="integer"/>
这是我在 SubscriptionFragment.kt
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return FragmentSubscriptionBinding.inflate(inflater, container, false).let {
this.binding = it
bind(skuDetailsList)
it.root
}
}
这是我绑定视图的地方
private fun bind(skuList: MutableList<SkuDetails>) {
binding?.let {
if (skuList.isNotEmpty()) {
it.week = skuList[0]
it.month = skuList[1]
it.year = skuList[2]
it.fragment = SubscriptionFragment@this
}
}
}
我尝试在我的应用程序中添加这些行 gradle.properties
android.databinding.enableV2 = true
android.enableExperimentalFeatureDatabinding = true
我已将这些添加到我的应用程序中 gradle
kapt 'com.android.databinding:compiler:3.1.4'
kapt {
generateStubs = true
}
configurations.all {
resolutionStrategy {
force 'com.android.support:support-annotations:23.1.1'
}
}
这里我绑定了自定义属性,需要在我膨胀的自定义视图中设置自定义 getters/setters
编辑:
例子
public class ColorPicker extends View {
private int color;
public void setColor(int color) {
this.color = color;
invalidate();
}
public int getColor() {
return color;
}
//...
}
这是 xml 的样子
<com.example.myapp.ColorPicker
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:color="@{color}"/>