In android can we do some thing like R.string.navigation_item_1 = _userName.getText().toString() where _userName is a TextView and navigation_item_1 is a string name in strings.xml. If not then what is the right procedure to pass a string from MainActivity to strings.xml
Asked
Active
Viewed 100 times
2 Answers
2
You can not customize the resources (no matter if string, drawable or what) in android at run time. The res folder could not be modified programmatically at all. For example you could not change a drawable at run time.
More answers to a similar question here: Change value of R.string programically
If you need a string value to be saved in your app, you could use SharedPrefferences
for example

Community
- 1
- 1

Gabriella Angelova
- 2,985
- 1
- 17
- 30
0
The answer is simple: you can't.
All xml resources files can't be modified during runtime. You can still assign that _userName.getText().toString()
to a public instance variable but you can't add it to some resources which reference is created during build process.

Giorgio Antonioli
- 15,771
- 10
- 45
- 70