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.

Answers


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:

A.s

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

After loop all elements same

c# arrays element

I want to assign value to elements of my array. after running this, all elements of ListResults are same as last element of ListROI.

Unsetting a variable vs setting to ''

php variables unset

Is it better form to do one of the following? If not, is one of them faster than the other?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.