[Solved] How to assign a value to a variable in Android studio


It seems like you really need to go back and start with the basics of Android and Internationalization. It is not possible to update a resource at runtime, as you have correctly discovered, so it is your approach that needs to change.

Here is an example:

TextView text;
String value = getString(R.string.knife);
text.setText(value);

It seems that onClick you try to do something like:

setString(R.string.knife, "sword");

Which is impossible. Instead, you need to have the two strings as separate resources and then switch your value to the new resource when needed. So simply:

value = getString(R.string.sword);
text.setText(value); //and reset the display

0

solved How to assign a value to a variable in Android studio