GiftAdapter.java
1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.cnlive.gundam.video.adpter;
import android.content.Context;
import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.cnlive.gundam.video.model.GiftModle;
import java.util.List;
/**
* @author 陈硕
* @time 2017/5/27 16:04
* @desc ${TODD}
*/
public class GiftAdapter extends RecyclerView.Adapter<GiftAdapter.RVHolder> {
private Context mContext;
private List<GiftModle> mDataList;
private int mLayoutId; // 条目布局文件ID
private int mVariableId; // DataBinding变量ID
public GiftAdapter(Context context, List<GiftModle> list, int layoutId, int variableId) {
this.mContext = context;
this.mDataList = list;
this.mLayoutId = layoutId;
mVariableId = variableId;
}
@Override
public RVHolder onCreateViewHolder(ViewGroup parent, int viewType) {
ViewDataBinding binding = DataBindingUtil.inflate(LayoutInflater.from(mContext), mLayoutId, parent, false);
RVHolder holder = new RVHolder(binding.getRoot());
holder.binding = binding;
return holder;
}
@Override
public void onBindViewHolder(RVHolder holder, final int position) {
holder.binding.setVariable(mVariableId, mDataList.get(position));
holder.binding.executePendingBindings();
}
@Override
public int getItemCount() {
return mDataList == null ? 0 : mDataList.size();
}
class RVHolder extends RecyclerView.ViewHolder {
ViewDataBinding binding;
RVHolder(View view) {
super(view);
}
}
}