Android的 - 从独特的整数获取资源(字符串) [英] android - get a resource (a string) from its unique integer
本文介绍了Android的 - 从独特的整数获取资源(字符串)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要做到以下几点:
我想打一个很简单的Gallery应用程序。所以我想选择的图像的路径,并将其作为一种资源。我在String.xml设置。
所以我有另一个类,需要选择的路径通过其加载的所有图像。
类imageHolder的
{
公共imageHolder的()
{
这个(R.string.image_dir);
//问题就在这里 - R.string.image_dir返回一个唯一的INT,而我真正需要的是字符串。我怎样才能得到它?
}
公共imageHolder的(字符串路径)
{
.........非标准程序.....
}
}
解决方案
使用的getString(渣油)
,但你需要一个上下文
对象虽然。
这是上下文
,这样的活动中,你可以写 this.getString(R.string.image_dir)的功能;
或者你可以跳过这
共...
I want to do the following:
I want to make a very simple gallery application. So I'd like to select a path for the images and set it as a resource. I set it in String.xml.
So I have another class, which needs the selected path to load all the images from it.
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.....
}
}
解决方案
Use getString(resID)
but you'll need a Context
Object though.
It's a Function of Context
, so within an Activity you can write this.getString(R.string.image_dir);
or you can skip this
altogether...
这篇关于Android的 - 从独特的整数获取资源(字符串)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文