class EntryAdapter extends BaseAdapter public static final int TYPE_CO

 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
class EntryAdapter extends BaseAdapter {
public static final int TYPE_COUNT = 2;
private static final int TYPE_TIPS = 0;
private static final int TYPE_EVENT = 1;
private Context context;
private List<Entry> entries;
public EntryAdapter(Context context, List<Entry> entries) {
this.context = context;
this.entries = entries;
}
@Override
public int getCount() {
return entries.size() + 1;
}
@Override
public Object getItem(int position) {
Object item = null;
if (entries != null && !entries.isEmpty()) {
if (position == 0) {
Entry entry = entries.get(0);
if (entry != null) {
item = entry.getMagictouchs();
}
} else {
item = entries.get(position - 1);
}
}
return item;
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int position, View view, ViewGroup viewGroup) {
int viewType = getItemViewType(position);
switch (viewType) {
case TYPE_TIPS: {
// Creating view for tips
break;
}
case TYPE_EVENT: {
// Creating view entry
break;
}
}
return view;
}
@Override
public int getItemViewType(int position) {
return position == 0 ? TYPE_TIPS : TYPE_EVENT;
}
@Override
public int getViewTypeCount() {
return TYPE_COUNT;
}
}