Skip to content

Instantly share code, notes, and snippets.

@aymenjegham
Last active July 17, 2019 01:40
Show Gist options
  • Save aymenjegham/d1eb396a7f73653bc1bda0259f6f471c to your computer and use it in GitHub Desktop.
Save aymenjegham/d1eb396a7f73653bc1bda0259f6f471c to your computer and use it in GitHub Desktop.
public class ContactAdapter extends RecyclerView.Adapter<contactAdapter.ContactHolder> {
private List<Contact> contacts = new ArrayList<>();
private Context cxt;
String telnum;
Activity activity;
@Override
public ContactHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.contact_item, parent, false);
return new ContactHolder(itemView);
}
@Override
public void onBindViewHolder(ContactHolder holder, int position) {
Contact currentContact = contacts.get(position);
holder.textViewTitle.setText(currentContact.getTitle());
if((!currentContact.equals(null))){
if (currentContact.getNumone() != null ) {
holder.numone.setVisibility(View.VISIBLE);
holder.imageview1.setVisibility(View.VISIBLE);
String str = currentNote.getNumone().replaceAll("\\s+","");
holder.numone.setText(str);
}
//Apply Logic related to Contact attributes here (same for getNumone)
}
@Override
public int getItemCount() {
return contacts.size();
}
public void setContacts(List<Contact> contacts, Context cxt, Activity activity) {
this.contacts = contacts;
this.cxt=cxt;
notifyDataSetChanged();
this.activity=activity;
}
class ContactHolder extends RecyclerView.ViewHolder {
private TextView textViewTitle;
private TextView numone;
private TextView numtwo;
private TextView numthree;
private TextView numfour;
private ImageView imageview1,imageview2,imageview3,imageview4;
public ContactHolder(View itemView) {
super(itemView);
textViewTitle = itemView.findViewById(R.id.text_view_title);
numone = itemView.findViewById(R.id.numone);
numtwo=itemView.findViewById(R.id.numtwo);
numthree=itemView.findViewById(R.id.numthree);
numfour=itemView.findViewById(R.id.numone2);
imageview1=itemView.findViewById(R.id.phoneiv2);
imageview2=itemView.findViewById(R.id.phoneiv);
imageview3=itemView.findViewById(R.id.phoneiv1);
imageview4=itemView.findViewById(R.id.phoneiv3);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment