java - getResources() from within an enumeration -- Android Studio -


I just started Android development Now, I have a enumeration Want to make Within that calculation, I want to assign a name to each enum-object. I want to get that name from my project resources ( res / values ​​/ strings.xml )

But from within the counting type, I can not call getResources () .getString (R.string.string_name) .

Is this because the calculation does not extend an activity or something?

How can I get the string anyway from the resources?

Thank you!

PS is not the foundation of counting within a class. If it is possible, then I want to put it as a separate file.

getResources () .getString () only getActivity () There is a short story for. GetResources () GetString () .

Then getResources () is still dependent on a reference (activity, piece, reference, etc.).

To overcome this, I personally extended the application class and made available public static references, so that you can always use resources and this kind of complete application, no matter if you Activity or in any POJO

Example:

  Public class IApp applications expanded {public static reference reference; @ Override Public Empty on Create () {Super. Connet (); Context = getApplicationContext (); }}   

With it, you can always call:

  MyApp.context.getResources (). GetString (xxxx);    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -