1

Ok this is going to be worded weird but I was wondering if there was a way to set one of the string values in values/strings.xml to a static final variable from one of the .java files. For example say I have the following basic class:

public class ConstantValue {
     public static final String VALUE = "custom val";
}

and I would get this value in the strings.xml file like so:

idea code

 <string name="custom_val">com.package.ConstantValue.VALUE</string>

Is there any way to do this?

1
  • 1
    I don't think this is possible, because I believe that strings.xml is compiled into a class of its own before the build gets to your actual activity source code. This is why the string bundle is available for use in your Java code. I could not find documentation on this, hence this remains as a comment. Commented Aug 12, 2017 at 10:55

2 Answers 2

3

This is not possible because string.xml resources are added to R.java, and R.java is an auto generated file contains all your resources used in the project. and if you want to change R.java you can't.

This is a basic thing in Android. You have to read Android Developers documents, then you will get good knowledge about it.

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

Comments

2

It is not possible, because strings.xml is precompiled file. Use SharedPreferences to save runtime-depending strings.

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.