-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathContactAdapter.java
More file actions
64 lines (51 loc) · 1.79 KB
/
ContactAdapter.java
File metadata and controls
64 lines (51 loc) · 1.79 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
package androidbuffer.com.readcontactdemo;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.util.List;
/**
* Created by incred-dev on 6/7/18.
*/
public class ContactAdapter extends RecyclerView.Adapter<ContactAdapter.MyViewHolder>{
private List<ContactModel> contactModelList;
ContactAdapter(List<ContactModel> contactModelList) {
this.contactModelList = contactModelList;
}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_contact, parent, false);
return new MyViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
ContactModel model = contactModelList.get(position);
if (model != null){
if (model.getName() != null){
holder.name.setText(model.getName());
}
if (model.getNumber() != null){
StringBuffer buffer = new StringBuffer();
for (String number:model.getNumber()){
buffer.append(number).append("\n");
}
holder.number.setText(buffer);
}
}
}
@Override
public int getItemCount() {
return contactModelList.size();
}
class MyViewHolder extends RecyclerView.ViewHolder {
TextView name, number;
MyViewHolder(View itemView) {
super(itemView);
name = itemView.findViewById(R.id.tvName);
number = itemView.findViewById(R.id.tvNumber);
}
}
}