(Android Xamarin)获取资源字符串值而不是int [英] (Android Xamarin) Get Resource string value instead of int

查看:62
本文介绍了(Android Xamarin)获取资源字符串值而不是int的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Im just starting to create a simple android app with the use of Xamarin using VS2012. I know there is a type of Resource just for strings. In my resource folder, i have an xml file like this:

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

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

In my code, I want to use the values of those resources like:

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

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

I know that Resource.String.<key> returns an integer so I cant use the code above. I am hoping that recordTable variable will have a value of records.

有没有一种方法可以将那些资源字符串的值用作代码的字符串变量?

Is there a way I can use the value of those resource string for my code's string variables?

推荐答案

使用

try it as using Resources.GetString for getting string from string Resources

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 Xamarin)获取资源字符串值而不是int的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆