I am trying to populate a RecyclerView with a custom adapter. This Adapter takes in a model that has setters and getters. This model contains three parameters: String username, int proPic, and int bckgImg. What i am trying to achieve is a RecyclerView with an alphabetical sorted list. I populate the model by using the following code:
private ArrayList<FriendsModel> friendsData = new ArrayList<>(0);
friendsData.add(new FriendModel("Erick", R.drawable.default_pro_pic, R.drawable bckgImg);
After i am done with populating 5 objects of the FriendModel, i then proceed to compare the characters found in the ArrayList:
for(char alph = 'A'; alph <= 'Z'; alph++){
List<String> friends = getFriends(alph);
if(friends.size() > 0){
//Populate the Sorted Alphabetical view
}
}
private List<String> getFriends(char alph) {
//Empty List used to populate when comparing existing model to alphabet
List<String> friends = new ArrayList<>();
//5 objects of FriendsData with three parameters
for (int i = 0; i < friendsData.size(); i++){
//If the first string parameter character at position 0 is equal to alph
if(friendsData.get(i).toString().charAt(0) == alph){
friends.add(friendsData.get(i).toString());
}
}
return friends;
}
I am not sure if i am doing this correctly, what is the adequate or correct way to compare the characters in an ArrayList based on its model?