1

I want to convert my int expression obtained with this :

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_full_screen_image);
    imageViewFullScreen = findViewById(R.id.imageView_fullscreen);
    textViewFullScreen = findViewById(R.id.textView_fullscreen);
    try
    {
        Bundle bundle = getIntent().getExtras();
        imageId = bundle.getInt("imageId");
    }

into a String expression, but when I try to do it, it doesn't work.

I try to put it in a TextView, with the int expression I have the right thing, but with String I only have numbers and not text.

I want to do that to cut a part of String which interest me.

There are solution to have what I want whitout passing by a String ? or to convert correctly my int expression ?

I've try to do this :

imageViewFullScreen.setImageResource(imageId);
        textViewFullScreen.setText("");
        textViewFullScreen.append("Ref : " + imageId);

I want to have : res/drawable/cata_01jpg, but I have : 2131099745

thank's for all !

2 Answers2

0

The number you have is a resource identifier. You can use the Resources class to find information about the resource it refers to. This class has several methods, I don't know which one is most useful for you but getResourceEntryName sounds like a close match.

String name = getResources().getResourceEntryName(imageId);
Joni
  • 108,737
  • 14
  • 143
  • 193
0

You can use this function that returns the path with the name of the resource:

    String path = getPath(R.drawable.icon);
    public String getPath(int id) {
    return Uri.parse("res/drawable/" + getResources().getResourceEntryName(id)).toString();
}
Cardstdani
  • 4,999
  • 3
  • 12
  • 31