Of course i know what does this error mean, but i don't know how to remove this. Now i'm trying with
private void removeFriendFromList() {
List<Friend> copy = new ArrayList<Friend>(globalSearchFriends);
for (Friend friend : globalSearchFriends) {
if (friend.equals(remove)) {
copy.remove(friend);
}
}
}
But this doesn't work. This is my globallist
private List<Friend> globalSearchFriends = new ArrayList<>();
I'm trying iterating too, but it didn't work or i did something bad.
Also i need to use it here: where i search for a friend in api, this is working like when i input text in EditText then in my adapter i see that user, but this work only for few members, always when i search like "andrew" and then i search "youko" i get the error.
private void serachFriend(final String query) {
etGlobalSearch.addTextChangedListener(new TextWatcherAdapter() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
FindFriend request = new FindFriend();
request.query = query;
request.query = s.toString().toLowerCase().trim();
backend.findFriend(request).enqueue(new Callback<ResponseFindFriend>() {
@Override
public void onResponse(Call<ResponseFindFriend> call, Response<ResponseFindFriend> response) {
synchronized (globalSearchFriends) {
globalSearchFriends.clear();
removeFriendFromList();
try {
if (response == null)
throw new Exception();
if (!response.isSuccessful())
throw new Exception();
if (response.body() == null)
throw new Exception();
if (response.body().results == null)
throw new Exception();
globalSearchFriends = response.body().results;
} catch (Exception e) {
Log.d("Blad", "sobie");
} finally {
gatherResults();
}
}
}
@Override
public void onFailure(Call<ResponseFindFriend> call, Throwable t) {
synchronized (globalSearchFriends) {
globalSearchFriends.clear();
removeFriendFromList();
gatherResults();
}
}
});
}
});
}
private void removeFriendFromList() {
List<Friend> copy = new ArrayList<Friend>(globalSearchFriends);
for (Friend friend : globalSearchFriends) {
if (friend.equals(remove)) {
copy.remove(friend);
}
}
}
private void gatherResults() {
removeFriendFromList();
for (Friend f : globalSearchFriends)
globalSearchFriends.add(f);
findedFriendsAdapter.setFriendList(globalSearchFriends);
}
Any kind of help associated, Have a nice day! :)
Edit I got error on this case.
java.util.ConcurrentModificationException
for (Friend f : globalSearchFriends)
globalSearchFriends.add(f);
findedFriendsAdapter.setFriendList(globalSearchFriends);
And on log i have:
at java.util.ArrayList$ArrayListIterator.next