简体   繁体   中英

Integer resource not what expected

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?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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