I have a method where I change the picture on the page by checking the name with the variable heroNameInPage , which I already know.
private void setImage() { ImageView img = findViewById(R.id.imageHero); switch (heroNameInPage) { case "Bar": img.setImageResource(R.drawable.Bar); break; case "Asmon": img.setImageResource(R.drawable.Asmon);break;}} There are several hundreds or thousand of such cases planned, so I want to optimize the code. On ImageView objects that are located on other pages, I have a tag for each ImageView. How do I pull out a tag and compare it with heroNameInPage to change the resource for img ??? There is something like this pattern:
ImageView item; for (int idF = 0; idF < 99999999; idF++){ item = findViewById(R.id.idF); if (heroNameInPage.equals(item.getTag().toString())){ img.setImageResource(item.getImageResource); }
Mapwith tags as keys or better inLruCacheto lower the chances of flying into the OOM. - woesss