1

I want to change the text on some buttons dynamically. All necessary text is saved at the strings.xml and the reference name is saved in a Json Object.

Anyone knows how i can get the data from strings.xml for my setText function?

JSONObject e = Options.getJSONObject(i); 
//The Name for strings.xml
String name = e.getString("name");

Resources res = getResources();
button1.setText(String.format(res.getString(R.string. ??????????? )));
Ben James
  • 121,135
  • 26
  • 193
  • 155
user1488243
  • 2,337
  • 4
  • 15
  • 7

2 Answers2

2

Use something like this

getResources().getIdentifier(name, "string", “com.main.package”));

or better:

getResources().getIdentifier(name, "string", getPackageName()));
User
  • 31,811
  • 40
  • 131
  • 232
0

You can get the any string from String.xml by

 getString(R.string.string_name); 
ashutosh
  • 759
  • 5
  • 13
  • 34