So my problem is that when i try to sort the albums, the album title and album art are wrong.
I tried sorting the album ids but that doesn\'t fix it because album id hav
Without changing much in your code, you can achieve what you intend by sorting the Songs using a Comparator. Comparator can be used whenever you need to sort the objects using one of its properties (which is album name in your case for the QuerySongs
object)
In your getAlbumsId
method, add following
public ArrayList getAlbumsId() {
ArrayList albumids = new ArrayList();
Collections.sort(songs, new Comparator() {
@Override
public int compare(QuerySongs o1, QuerySongs o2) {
return o1.getAlbum().compareTo(o2.getAlbum());
}
});
for (QuerySongs song : songs){
Long albumid = song.getAlbumID();
if (! albumids.contains(albumid)) {
albumids.add(albumid);
}
}
return albumids;
}
Above will mutate the songs
object, if you don't want that to happend, make a copy of it. Crux is to use comparator to sort the songs.