gpt4 book ai didi

android - (Android Xamarin) 获取资源字符串值而不是 int

转载 作者:IT老高 更新时间:2023-10-28 22:13:47 26 4
gpt4 key购买 nike

我刚刚开始使用 VS2012 使用 Xamarin 创建一个简单的 android 应用程序。我知道有一种类型的资源只用于字符串。在我的资源文件夹中,我有一个这样的 xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="RecordsTable">records</string>
<string name="ProjectTable">projects</string>
<string name="ActivitiesTable">activities</string>
</resources>

在我的代码中,我想使用这些资源的值,例如:

string recordTable = Resource.String.RecordsTable; //error, data type incompatibility

我知道 Resource.String.<key>返回一个整数,所以我不能使用上面的代码。我希望 recordTable变量的值为 records .

有没有办法可以将这些资源字符串的值用于我的代码的字符串变量?

最佳答案

尝试使用 Resources.GetString从字符串资源中获取字符串

Context context = this;
// Get the Resources object from our context
Android.Content.Res.Resources res = context.Resources;
// Get the string resource, like above.
string recordTable = res.GetString(Resource.String.RecordsTable);

关于android - (Android Xamarin) 获取资源字符串值而不是 int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15897042/

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