Set resource ID of String in code

Is there a way to set the ID of a string in code, so I can call the string in other Activities by R.strings.codegenstring. I can't predefine them in the string.xml since there will be a variable amount of code generated strings.


No. But you can define a String as static

public class A {
    public static String s;

    public void yourStringGeneratingFunction() {
        s = "blahblah";

And access it from another class by:


No, there no way. To call string by R.string.codegenstring you must define public static string variable in R class. But R class are built by Android during compiling and you shouldn't modify it.

Need Your Help

Assign macro to buttons across multiple sheets

excel excel-vba

How can I assign this macro to buttons across multiple sheets; ie. irrespective of whether a button's name is "Button 1" or "Button 2"?

Concatenate elements of a list

python string concatenation

I have a list like l=['a', 'b', 'c']