AbsCommonAdapter.java
3.4 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package com.lijinji.call.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public abstract class AbsCommonAdapter<T> extends BaseAdapter {
protected LayoutInflater mInflater;
protected Context mContext;
protected List<T> mDatas;
protected final int mItemLayoutId;
protected Context app;
public AbsCommonAdapter(Context context, int itemLayoutId, Context app) {
this.mContext = context;
this.mInflater = LayoutInflater.from(mContext);
this.mItemLayoutId = itemLayoutId;
this.app = app;
mDatas = new ArrayList<T>();
}
public AbsCommonAdapter(Context context, int itemLayoutId) {
this(context, itemLayoutId, null);
}
public void addItemData(T mBean, boolean isRefresh) {
mDatas.add(mBean);
if (isRefresh) {
notifyDataSetChanged();
}
}
public void addItemData(T mBean, int index, boolean isRefresh) {
mDatas.add(index, mBean);
if (isRefresh) {
notifyDataSetChanged();
}
}
public void addItemData(Collection<? extends T> mCommonbeans, int index, boolean isRefresh) {
mDatas.addAll(index, mCommonbeans);
if (isRefresh) {
notifyDataSetChanged();
}
}
public void addItemData(Collection<? extends T> mCommonbeans, boolean isRefresh) {
mDatas.addAll(mCommonbeans);
if (isRefresh) {
notifyDataSetChanged();
}
}
public void addData(List<T> mCommonbeans, boolean isMore) {
if (isMore) {
if (mCommonbeans != null) {
mDatas.addAll(mCommonbeans);
}
} else {
mDatas.clear();
if (mCommonbeans != null) {
mDatas.addAll(mCommonbeans);
}
}
notifyDataSetChanged();
}
public void remove(int pos) {
if (mDatas != null && mDatas.size() > 0) {
mDatas.remove(pos);
notifyDataSetChanged();
}
}
public void clearData(boolean clear) {
if (clear) {
if (mDatas != null && mDatas.size() > 0) {
mDatas.clear();
notifyDataSetChanged();
}
}
}
@Override
public int getCount() {
return mDatas.size();
}
@Override
public T getItem(int position) {
if(mDatas!= null &&position>=0&&position<=(mDatas.size()-1)){
return mDatas.get(position);
}
return null ;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final AbsViewHolder viewHolder = getViewHolder(
position, convertView, parent
);
convert(viewHolder, getItem(position), position);
return viewHolder.getConvertView();
}
public abstract void convert(AbsViewHolder helper, T item, int pos);
private AbsViewHolder getViewHolder(int position, View convertView, ViewGroup parent) {
return AbsViewHolder.get(
mContext, convertView, parent, mItemLayoutId, position
);
}
public List<T> getDatas() {
return mDatas;
}
}