Android的:从XML资源整 [英] Android: integer from xml resource
问题描述
我如何要修改我的XML资源,或者是XML文件,我必须创造,你如何处理字符串值做访问整数值?
How do I have to modify my XML resources, or what XML file do I have to create, to access integer values how you do it with string values?
例如,在code我想说的:
For example, in the code I want to say:
ProgressDialog progressBar = new ProgressDialog(getContext());
progressBar.setMax(getInteger(R.integer.maximum));
这可能吗?
推荐答案
是的,它是可能的,它是这样的:
Yes it is possible, it would look like this:
1)创建文件夹/ RES /价值/称为integers.xml一个xml资源文件。
您可以自由,只要你想给它任何名称,但选择一个是显而易见的。
You are free to give it any name as you want, but choose one that is obvious.
2)的在资源文件,创建整数值。
您的文件,那么看起来就像这样:
Your file then looks something like that:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="maximum">100</integer>
...
</resources>
3)引用的整数值在Java code这样的:
这是从的getString(),你得需要一点弯路。有一点不同
It's a bit different from the getString(), you have to take a little detour.
ProgressDialog progressBar = new ProgressDialog(getContext());
int max = getContext().getResources().getInteger(R.integer.maximum);
progressBar.setMax(max);
希望帮助任何人谁拥有了同样的问题。
Hope that helps anybody who has the same question.
这篇关于Android的:从XML资源整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!