1

In PHP

$variable_name = "LOREM_IPSUM";
$x = "variable_name";


echo $x;     // Print "variable_name"
echo $$x;    // Print "LOREM_IPSUM"

Java equivalent to get a variable named like the string contained in another variable.

For example to avoid:

 case 0:
     rb0.setEnabled(true);
     break;
 case 1:
     rb1.setEnabled(true);
     break;
 case 2:
     rb2.setEnabled(true);
     break;
...
Gianluca Demarinis
  • 1,964
  • 2
  • 15
  • 21

2 Answers2

0

You can use an Map for instance, where the key is the id and the value the radiobutton then you just have to get on the map to get the radiobutton. Don't forget java is more verbose than PHP. If you need to access the variable by its name you can use reflection https://docs.oracle.com/javase/tutorial/reflect/

Timo
  • 497
  • 10
  • 21
0

Sounds like you want to use something like eval() in javascript.

I haven't tested it so I don't even know if this will work but maybe you can try something like the ScriptEngine class and evaluate it as a Javascript string.

ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("js");
String result = engine.eval(x);

Look here on how to import it in Android

Denny
  • 1,766
  • 3
  • 17
  • 37