简体   繁体   English

整数资源不是预期的

[英]Integer resource not what expected

I have the following integer resources in my strings.xml file 我的strings.xml文件中有以下整数资源

<item type="integer" name="pID" format="integer">374</item>
<item type="integer" name="vID" format="integer">3468</item>

I want to call them from my code to get 374 and 3468. 我想从我的代码中调用它们以获取374和3468。

However, when I output to Logcat... 但是,当我输出到Logcat时...

Log.d("MainActivity.onCreate","pID: "+R.integer.pID+" vID: "+R.integer.vID);

I see the following... 我看到以下...

pID: 2131230720 vID: 2131230721

Why are R.integer.vID and R.integer.pID returning ints other than 3468 and 374 respectivley? 为什么R.integer.vIDR.integer.pID返回3468和374以外的整数?

You are printing out the resource IDs. 您正在打印资源ID。 Use Resources.getInteger(resourceId) instead. 请改用Resources.getInteger(resourceId)

http://developer.android.com/guide/topics/resources/more-resources.html#Integer http://developer.android.com/guide/topics/resources/more-resources.html#Integer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM