我试图使用示例项目android-sunflower绑定一个viewmodel,但目前的问题是在尝试构建该项目时,我会遇到错误 error: cannot find symbol symbol: class FragmentShopBindingImpl location: package {{packageName}}.databinding
在类 DataBindinMapperImpl
中。我不太确定我错过了什么,因为我已经添加了示例项目中的所有内容。类FragmentShopBindingImpl
没有被生成,或者它不应该被生成吗?由于我在android sunflower示例中看不到任何以'Impl'结尾的类。
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val factory = InjectorUtils.provideShopViewModelFactory(context!!)
val shopViewModel = ViewModelProviders.of(this, factory)
.get(ShopViewModel::class.java)
val binding = DataBindingUtil.inflate<FragmentShopBinding>(
inflater, R.layout.fragment_shop, container, false).apply {
viewModel = shopViewModel
lifecycleOwner = this@ShopFragment
}
return binding.root
}
布局:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="viewModel"
type="{{packageName}}.viewmodel.ShopViewModel" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".fragments.ShopFragment">
<TextView
android:text="@{viewModel}"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</layout>
生成文件的图像(忽略{{packageName}}):