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); } 
  • item = findViewById (R.id.idF) - does it work? - Enikeyshchik
  • Unfortunately not) I don’t know how to search among objects by ID - Ainur Fatkullin
  • Pseudocode template - Ainur Fatkullin
  • Maybe somehow through Assets? - Ainur Fatkullin
  • Yes, it can be done in different ways, but it is not clear what you are trying to do - explain more fully. And that there are different pages - these are different Activities? The simplest thing is to parallelly stack in the Map with tags as keys or better in LruCache to lower the chances of flying into the OOM. - woesss

0