0

I have a bunch of strings in strings.xml, named eg a1, a2, a3, a4:

<string name="a1">url1</string>
<string name="a2">url2</string>
<string name="a3">url3</string>
<string name="a4">url4</string>

I've setup a randomiser to create a random number, eg between 1 and 4

I've then created a variable to add the letter 'a' to the random number eg a3

String url = "a" + (+randint);

This prints 'a3' successfully:

System.out.println((url));

I'm now trying to display the contents of the 'a3' string in textview or even just System.out.((url)) but can't figure out how to expand the variable as url3. At best I can only pull out 'a3'. Any ideas?

KERR
  • 1,312
  • 18
  • 13
  • This seems to have a correct answer: https://stackoverflow.com/questions/3476430/how-to-get-a-resource-id-with-a-known-resource-name – terrorrussia-keeps-killing Jan 07 '21 at 11:20
  • `I've setup a randomiser to create a random number, eg between 1 and 4` why aren't you just using this random value to pull one of the url values from an array ? you're saying that you have `a3` and you want to display `url3` ? – a_local_nobody Jan 07 '21 at 11:20

0 Answers0