package com.android.example.bindingdemo; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.ViewGroup; import android.databinding.DataBindingUtil; import android.databinding.ViewDataBinding; abstract public class DataBoundAdapter extends RecyclerView.Adapter> { final int mLayoutId; final Class mBinderInterface; public DataBoundAdapter(int mLayoutId, Class mBinderInterface) { this.mLayoutId = mLayoutId; this.mBinderInterface = mBinderInterface; } @Override public DataBoundAdapter.DataBoundViewHolder onCreateViewHolder(ViewGroup viewGroup, int type) { T binder = DataBindingUtil.inflate(LayoutInflater.from(viewGroup.getContext()), mLayoutId, viewGroup, false); return new DataBoundViewHolder(binder); } static class DataBoundViewHolder extends RecyclerView.ViewHolder { public final T dataBinder; public DataBoundViewHolder(T mViewBinder) { super(mViewBinder.getRoot()); this.dataBinder = mViewBinder; } } }