gpt4 book ai didi

java - 如何在 Android 中使用整数资源?

转载 作者:行者123 更新时间:2023-11-29 05:25:30 25 4
gpt4 key购买 nike

我正在尝试使用存储在 values 文件夹中的一个整数,但有些东西不正确。这是 XML:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="numb">5</integer>
</resources>

这是主要 Activity :

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d("testLog", R.integer.numb+"");

}

但是当我运行它时输出是:

04-02 14:08:30.044: D/test(14839): 2131099648

为什么我得到的是 get 5?

最佳答案

使用

int value = getResources().getInteger(R.integer.numb);

有关详细信息,请查看主题整数 下的文档。

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

引用文档

资源

The Android resource system keeps track of all non-code assets associated with an application. You can use this class to access your application's resources. You can generally acquire the Resources instance associated with your application with getResources().

getResources()Context的一个方法。

关于java - 如何在 Android 中使用整数资源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22811131/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com