gpt4 book ai didi

android - 从其唯一整数中获取资源(字符串)

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:34:39 24 4
gpt4 key购买 nike

我想做以下事情:

我想制作一个非常简单的图库应用程序。所以我想为图像选择一个路径并将其设置为资源。我在 String.xml 中设置了它。

所以我有另一个类,它需要选定的路径来从中加载所有图像。

class ImageHolder
{
public ImageHolder()
{
this(R.string.image_dir);
//problem is here - R.string.image_dir returns a unique int, while what I really need is the string. How can I get it...
}
public ImageHolder(String path)
{
.........standart procedure.....
}
}

最佳答案

使用 getString(resID) 但您需要一个 Context 对象。

它是 Context 的一个函数,所以在 Activity 中你可以写 this.getString(R.string.image_dir); 或者你可以跳过 this 完全...

关于android - 从其唯一整数中获取资源(字符串),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3694306/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com