Android Studio 3.1。
应用程序/的build.gradle:
android {
dataBinding {
enabled = true
}
xml文件的名称: preview_brand_item.xml
在我的适配器中:
import com.myproject.android.customer.databinding.PreviewBrandItemBinding;
public class PreviewBrandSortAdapter extends PreviewBaseSortAdapter {
@Override
protected int getLayoutIdForPosition(int position) {
return R.layout.preview_brand_item;
}
@Override
protected void setClickHandler(ViewDataBinding binding) {
PreviewBrandItemBinding previewBrandItemBinding = (PreviewBrandItemBinding) binding;
previewBrandItemBinding.setClickHandler(this);
}
}
这里是父适配器:
public abstract class PreviewBaseSortAdapter extends RealmRecyclerViewAdapter {
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
ViewDataBinding binding = DataBindingUtil.inflate(layoutInflater, viewType, parent, false);
setClickHandler(binding);
return new PreviewBaseViewHolder(binding);
}
}
但 PreviewBrandItemBinding 未生成,因此我收到错误:
myproject\app\src\main\java\com\myproject\android\customer\ui\adapter\PreviewBrandSortAdapter.java:17: error: package com.myproject.android.customer.databinding does not exist
import com.myproject.android.customer.databinding.PreviewBrandItemBinding;