I have added Alphabetic headers to contact list
new ReadContactTask(context, showProgressDialog,new OnContactReadListener() {
@Override
public void onContactRead(List dummyList) {
ArrayList latestPhoneContacts = new ArrayList<>();
if(dummyList!=null && dummyList.size()>0)
{
tvNoResult.setVisibility(View.GONE);
for(ContactItem contactItem : dummyList){
String contactNameInCapital = "";
if(contactItem.getContactName()!=null && contactItem.getContactName().length()>2){
contactNameInCapital = contactItem.getContactName().substring(0,1).toUpperCase();
if(contactNameInCapital.charAt(0) != previousContact.charAt(0))
{
latestPhoneContacts.add(new ContactItem(contactNameInCapital.substring(0,1)));
latestPhoneContacts.add(contactItem);
}
else
{
latestPhoneContacts.add(contactItem);
}
previousContact = contactNameInCapital;
}
}
if(latestPhoneContacts!=null && latestPhoneContacts.size()>0)
contactListAdapter.addItems(latestPhoneContacts);
}
}
@Override
public void onContactEmpty() {
}
}).execute();
where
private String previousContact ="Zee";