Hi guys I have a problem with my list. I need to check if a string is equal to one of the strings in my arraylist. So far it's working if there is only one equal string that matches in the list. However, if there are two or more strings, only one is being matched.
This is what I've tried so far:
viewHolder.tv.setText(namesList.get(position));
viewHolder.tvEmailAddress.setText(emailsList.get(position));
if (ConnectionDetector.hasNetworkConnection(getActivity())) {
if(registeredContactsList != null) {
for(String email : registeredContactsList) {
if( emailsList.get(position).equals(email) ) {
Log.d(TAG, "Registered: " + email);
viewHolder.tvRegistered.setText("Add to Friends");
} else {
viewHolder.tvRegistered.setText("Invite");
}
}
} else {
viewHolder.tvRegistered.setVisibility(View.GONE);
}
} else {
viewHolder.tvRegistered.setVisibility(View.GONE);
}
UPDATE:
final int emailIndex = cursor.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA);
String contactId, displayName, emailAddress;
while (cursor.moveToNext()) {
contactId = cursor.getString(contactIdIndex);
displayName = cursor.getString(displayNameIndex);
emailAddress = cursor.getString(emailIndex);
idsList.add(contactId);
namesList.add(displayName);
emailsList.add(emailAddress);
}
I should get two
Add to Friends
in my listview. Assuming I have two strings matched in the arraylist.
Any ideas why I am getting only one string matched? Any help will be appreciated. Thanks.
emailsListandregisteredContactsListregisteredContactsListis not filled correctly, can you do a little test and log for us the content of both lists ?