-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathContactAdapter.java
More file actions
155 lines (117 loc) · 4.15 KB
/
ContactAdapter.java
File metadata and controls
155 lines (117 loc) · 4.15 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package fr.uha.contact;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Filter;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
public class ContactAdapter extends BaseAdapter {
private Context context;
ArrayList<Contact> liste = new ArrayList<Contact>();
ArrayList<Contact> searchContacts;
private CustomFilter filter;
public ContactAdapter(Context context) {
this.context = context;
this.searchContacts = this.liste;
}
public void ajout() {
Contact perso1 = new Contact("BART", "Alex", "00 00 01");
Contact perso2 = new Contact("BARTHELME", "Alexandre", "00 00 02");
Contact perso3 = new Contact("Munch", "Luc", "00004");
Contact perso4 = new Contact("ZNTONY ", "Sebastien", "00007");
liste.add(perso1);
liste.add(perso2);
liste.add(perso3);
liste.add(perso4);
}
@Override
public int getCount() {
return liste.size();
}
@Override
public Object getItem(int position) {
return liste.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View v, ViewGroup parent) {
if (v == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.contact_activity, null);
}
Contact val = liste.get(position);
TextView itemView = v.findViewById(R.id.textView);
itemView.setText(val.getNOM());
TextView itemView2 = v.findViewById(R.id.textView2);
itemView2.setText(val.getPRENOM());
return v;
}
public int size() {
return liste.size();
}
public Contact get(int index) {
return liste.get(index);
}
public Contact set(int index, Contact element) {
return liste.set(index, element);
}
public void addI(int index, Contact element) {
liste.add(index, element);
}
public boolean remove(Contact contact) {
return liste.remove(contact);
}
public boolean add(Contact contact) {
return liste.add(contact);
}
public Contact remove(int index) {
return liste.remove(index);
}
public static Comparator<Contact> ComparatorNom = new Comparator<Contact>() {
@Override
public int compare(Contact o1, Contact o2) {
return o1.getNOM().compareTo(o2.getNOM());
}
};
class CustomFilter extends Filter {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults results = new FilterResults();
if (constraint != null && constraint.length() > 0) {
constraint = constraint.toString().toLowerCase();
ArrayList<Contact> filters = new ArrayList<>();
for (int i = 0; i < searchContacts.size(); i++) {
if (searchContacts.get(i).toString().toLowerCase().contains(constraint)) {
filters.add(searchContacts.get(i));
}
}
results.count = filters.size();
results.values = filters;
} else {
results.count = searchContacts.size();
results.values = searchContacts;
}
return results;
}
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
liste = (ArrayList<Contact>) results.values;
notifyDataSetChanged();
}
}
public Filter getFilter() {
if (this.filter == null) {
this.filter = new CustomFilter();
}
return this.filter;
}
}