2012-09-27 43 views
0

我正在使用android SDK與Microsoft VS2010 C#。我想在我的C#代碼中使用my/resources/values/strings文件中的字符串值。這是一段說明我想要做什麼的代碼。我沒有得到字符串值。我知道資源ID是一個i​​nt,但我需要的是該ID後面的實際字符串值。在Mono中使用strings.xml for Android

 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; 
     } 
+1

您將有更好的運氣得到的回答你的問題,如果你減少非工作樣本到最小必要的代碼,以顯示錯誤。這樣做甚至可能幫助您找到解決方案!就目前而言,潛在的回答者在你的粘貼函數中理解太多了。 –

回答

5

正如您所注意到的,Resource.String.Enter是一個爲您生成的整數,您可以使用它來訪問字符串資源。您可以使用Android.Content.Res.Resources.GetString()方法訪問:

string enter = Resources.GetString(Resource.String.Enter); 
+0

謝謝!這很好用! – mrMagik3805