java - getResources() from within an enumeration -- Android Studio -
i've started android development
. now, want create enumeration
. each enum-object within enumeration, want assign name to. want name project resources (res/values/strings.xml
).
but within enumeration type, can't phone call getresources().getstring(r.string.string_name)
.
is because enumeration doesn't extend activity or something?
how can fetch strings resources anyway?
thanks!
p.s. enumeration not nested within class. if possible, want maintain seperate file.
p.p.s. i'm not experienced programmer.
p.p.p.s. forgive me english.
getresources().getstring()
shorthand getactivity().getresources().getstring()
.
so getresources()
still rely on having context (activity, fragment, context, etc).
to overcome this, extended application class , made public static context available, can access resources , such in entire application, no matter if you're in activity or pojo.
example:
public class myapp extends application { public static context context; @override public void oncreate() { super.oncreate(); context = getapplicationcontext(); } }
with this, can call:
myapp.context.getresources().getstring(xxxx);
java android android-studio
No comments:
Post a Comment