title: Change value of R.string programmatically?
body: <p>I'm looking for a way to change the value of a string resource dynamically. I have tried to use reflection but it claims 'invalid value for field'.</p>
  
  <p>I use the strings for values within the layout, but need to swap them out for different languages.</p>
  
  <p>Please see the attached code below.</p>
  
  <pre><code>public class Lang{
      public static void langInit(){
          java.lang.reflect.Field[] langStringFields = R.string.class.getFields();
  
          Log.d(Global.TAG,"--&gt; Lang Listing: " + langStringFields.length);
          Log.d(Global.TAG,"--&gt; Pref for language:");
  
          String prefInLang = Prefs.cPrefsGet.getString("in_lang","en");
  
          String fieldName = null;
          String fieldValue = null;
          String newFieldName = null;
  
          String tmpA = "one";
  
          for (int i=0; i&lt;langStringFields.length; i++){
              java.lang.reflect.Field field = langStringFields[i];
  
              fieldName = field.getName();
  
              try {
                  fieldValue = Global.gActivity.getString(field.getInt(R.string.class));
              } catch (Exception e) {
                  e.printStackTrace();
              }
  
              if (fieldName.substring(0,2).equals("lo")){
                  try {
                      newFieldName = R.string.class.getField(prefInLang + "_" + fieldName.substring(3)).getName();
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
                  Log.d(Global.TAG,"--&gt; Field: " + fieldName + "value: " + fieldValue + "new field:" + newFieldName);
                  try {
                      java.lang.reflect.Field field2 = Class.forName(R.string.class.getName()).getDeclaredField(newFieldName);
                      field2.setAccessible(true);
                      field2.set(R.string.class,tmpA.toString());
                  }catch (Exception e) {
                      e.printStackTrace();
                  }
              }
          }
      }
  }
  </code></pre>