When programming for Android sometimes you have to use static methods. But when you try to access you resources in a static method with getString(R.string.text)
you'll get an error. Making it static doesn't work.
Does anyone knows a good way around this? The resource files in Android are very helpful for creating things in different languages or making changes to a text.
A string resource provides text strings for your application with optional text styling and formatting. There are three types of resources that can provide your application with strings: String. XML resource that provides a single string.
Return a localized string from the application's package's default string table.
The XML resource files containing localized strings are placed in subfolders of the project's res folder.
One way or another, you'll need a Context for that... For static methods this probably means you need to pass along a Context when calling them.
You could use Resources.getSystem().getStringArray(android.R.array.done);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With