title: Accessing contents of R.string using a variable to represent the resource name
body: <p>I have a few strings which I need to translate and display. Those strings are in variables. I have the translation in the strings.xml file. </p>
  
  <p>I want to display the "translated version" of the string. For example, inside an Activity:</p>
  
  <pre><code>String name = "Water";
  TextView nameDisplay = new TextView(this).
  nameDisplay.setText(name);
  </code></pre>
  
  <p>In the strings file I have the definition</p>
  
  <pre><code>&lt;string name="Water"&gt;French word for Water&lt;/string&gt;
  </code></pre>
  
  <p>If I used something like this:</p>
  
  <pre><code>nameDisplay.setText(R.string.KnownName);
  </code></pre>
  
  <p>it would work. But in my case, the name is stored in a variable so I do not know what to do in  order for the setText method to function properly.</p>
  
  <p>My current workaround is </p>
  
  <pre><code>String translation = ""
  
  if(name == "Water") {
    translation = getString(R.string.Water);
  }
  else {
    ...
  }
  
  nameDisplay.setText(translation);
  </code></pre>
  
  <p>... but this does not scale very well.</p>
  
  <p>Any suggestions? </p>
  
  <p>Should I store the translated version in the variable?</p>