I need to get values from a Map by Adapter position i get from a RecyclerView.
As you can see each time i click on an Album Art i create a new array of album objects.
final Album[] albums = new Album[albumMap.size()];
for (Map.Entry<Integer,Album> e : albumMap.entrySet()){
albums[i++] = e.getValue();
}
Then i get the album like this: String selectedAlbum = albums[position].getAlbum();
But what if someone has like 10000+ albums on his device and each time an album is clicked a new array of album objects is created and i iterate through it just to get the album name.
Would this have an impact on performance if there are alot of albums present?
TL;DR Is this code bad?
Full code
@Override
public void onClickAlbum(int position, Map<Integer,Album> albumMap) {
if (getActivity() != null) {
int i = 0;
final Album[] albums = new Album[albumMap.size()];
for (Map.Entry<Integer,Album> e : albumMap.entrySet()){
albums[i++] = e.getValue();
}
String selectedAlbum = albums[position].getAlbum();
Main.getInstance().setSongsFilteredBy(SongsLibrary.getInstance().getSongsByAlbum(selectedAlbum));
Intent intent = new Intent(getActivity(), ListSongsActivity.class);
intent.putExtra("title", selectedAlbum);
startActivity(intent);
Toast.makeText(getActivity(), "test: " + selectedAlbum, Toast.LENGTH_SHORT).show();
}
}