1

我想转换由此获得的 int 表达式:

@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");
    }

变成一个字符串表达式,但是当我尝试这样做时,它不起作用。

我尝试将它放在 TextView 中,使用 int 表达式我有正确的东西,但使用 String 我只有数字而不是文本。

我想这样做来削减我感兴趣的字符串的一部分。

有什么解决方案可以通过 String 传递我想要的东西吗?或正确转换我的 int 表达式?

我试着这样做:

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

我想要:res/drawable/cata_01jpg,但我有:2131099745

谢谢大家!

4

2 回答 2

0

您可以使用此函数返回带有资源名称的路径:

    String path = getPath(R.drawable.icon);
    public String getPath(int id) {
    return Uri.parse("res/drawable/" + getResources().getResourceEntryName(id)).toString();
}
于 2020-07-06T13:18:44.347 回答
0

您拥有的数字是资源标识符。您可以使用 Resources 类来查找有关它所引用的资源的信息。这个类有几个方法,我不知道哪一个对你最有用,但getResourceEntryName听起来很接近。

String name = getResources().getResourceEntryName(imageId);
于 2020-07-06T13:08:21.160 回答