haijiang
2018-06-25 586f13d3aa93fc3fdfed65021b1a17a17acf3321
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
package com.moral.andbrickslib.baseadapter.recyclerview;
 
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
 
import com.moral.andbrickslib.baseadapter.recyclerview.base.ItemViewDelegate;
import com.moral.andbrickslib.baseadapter.recyclerview.base.ViewHolder;
 
import java.util.List;
 
/**
 * Created by zhy on 16/4/9.
 */
public abstract class CommonAdapter<T> extends MultiItemTypeAdapter<T>
{
    protected Context mContext;
    protected int mLayoutId;
    protected List<T> mDatas;
    protected LayoutInflater mInflater;
 
    public CommonAdapter(final RecyclerView v, final int layoutId, List<T> datas)
    {
        super(v, datas);
        mContext = v.getContext();
        mInflater = LayoutInflater.from(mContext);
        mLayoutId = layoutId;
        mDatas = datas;
 
        addItemViewDelegate(new ItemViewDelegate<T>()
        {
            @Override
            public int getItemViewLayoutId()
            {
                return layoutId;
            }
 
            @Override
            public boolean isForViewType( T item, int position)
            {
                return true;
            }
 
            @Override
            public void convert(ViewHolder holder, T t, int position)
            {
                CommonAdapter.this.convert(holder, t, position);
            }
        });
    }
 
    protected abstract void convert(ViewHolder holder, T t, int position);
 
 
}