I’m trying to return the sequence from a Collection and apply it to a TextView. When I set the text, only one value is set, the last of the sequence. When I print the sequence, to check it’s working, everything prints correctly. As far as I can tell, I’m doing this right by saying while the iterator hasNext(), get next() and in this case, the name of the track. I’ve tried a few other ways to set the Collection properly, but after researching how to use an Iterator and Collection a little more, I always end up back with this method. What is it I’m missing?
public static String getTopTracks(String mArtistName) {
String returnTopTracks = "";
Collection<Track> top = Artist.getTopTracks(mArtistName, key);
Iterator<Track> itr = top.iterator();
while (itr.hasNext()) {
returnTopTracks = itr.next().getName();
System.out.println(returnTopTracks);
}
return returnTopTracks;
}
You probably want to return your top tracks as a Collection
}