Faced the following situation: my activity causes another activity through Intent, adding to this Intent the name of the file that the invoked Intent should open (let it be for example p1). For each such p1 file, there is a corresponding image p1.jpg , which must be added to the ImageView for all the same called activity. So, is it possible for me to somehow make the opening of this picture a more universal method than for each file to make my own case , by type:

 switch (path){ case "p1": //добавить p1.jpg break; ... } 
  • can not do so? path + ". jpg" - danilshik
  • @danilshik, yes, but the image is added to my imageView through 'imageView.setImageResource (R.drawable.p1);' and I don’t know how to change it - Sergei Mikhailovskii
  • one
    And why not immediately pass the id , and not the name of the resource? - woesss

1 answer 1

From drawable by name gets like this:

imageView.setImageResource(getResources.getIdentifier(path, "drawable", getPackageName()));