我正在使用Android SDK与Microsoft VS2010 C#。我想在我的C#代码中使用my / resources / values / strings文件中的字符串值。这是一段代码,说明了我想要做的事情。我没有得到字符串值。我知道资源id是一个int,但我需要的是该id后面的实际字符串值。
void vx2OkButton_Click(object sender, EventArgs e)
{
Log.Info(LOG_TAG, "Hello from OkButton|Enter()button"); // also used as Enter button
strVx20kButtonText = vx2OkButton.Text.ToString();
mDwnLdCodeEnteredByUser = vxxDwnldCodeEntered.Text.Trim();
string strDwnldCodeOut = mActCode.Bad.ToString();
if(strVx20kButtonText == Resource.String.Enter.ToString())
{
if (mDwnLdCodeEnteredByUser.Length < 1)
{
vxxSystemMsgBox.SetText(Resource.String.FieldRequried_);
m_txvEnterDwnLdCode.SetTextAppearance(this,Resource.Color.Red);
return;
}
// verify the dwnldcodeenter by the user matches the assigned to user when at the time the downloaded the app
mDwnLoadStatus = VerifyDwnLoadCode(mDwnLdCodeEnteredByUser);
if (mDwnLoadStatus == mDwnLdStatCode.BadDwnLdCode.ToString())
{
vxxSystemMsgBox.SetText(Resource.String.InvalidValueEntered);
m_txvEnterDwnLdCode.SetTextAppearance(this, Resource.Color.Red);
return;
}
mActionCD = mActCode.Ok.ToString();
vx2OkButton.SetText(Resource.String.OkButtonText);
vxxSystemMsgBox.SetText(Resource.String.ThanksPressOkButton);
m_txvEnterDwnLdCode.SetTextAppearance(this,Resource.Color.White);
return;
}
答案 0 :(得分:5)
正如您所注意到的,Resource.String.Enter是为您生成的整数,可用于访问字符串资源。您可以使用Android.Content.Res.Resources.GetString()
方法访问它:
string enter = Resources.GetString(Resource.String.Enter);