Ryan
Ryan

Reputation: 747

Android: Set strings.xml value from .java file

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?

Upvotes: 1

Views: 1334

Answers (2)

akhilesh0707
akhilesh0707

Reputation: 6899

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.

Upvotes: 3

Valentun
Valentun

Reputation: 1711

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

Upvotes: 2

Related Questions