0

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

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.