Integer resource not what expected

扶醉桌前 提交于 2020-01-16 18:14:23

问题


I have the following integer resources in my strings.xml file

<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.

However, when I output to 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?


回答1:


You are printing out the resource IDs. Use Resources.getInteger(resourceId) instead.

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



来源:https://stackoverflow.com/questions/16112180/integer-resource-not-what-expected

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!