安卓的getString(R.string)的静态方法静态、方法、getString、string

2023-09-08 09:23:18 作者:Drowning.(溺死)

当编程为Android有时你必须使用静态方法。但是,当您尝试访问你的资源在静态方法与的getString(R.string.text),你会得到一个错误。使其静态不起作用。

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.

有谁知道解决这个好办法?在Android的资源文件是在不同的语言创造的东西或更改文本非常有益的。

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.

推荐答案

这种或那种方式,你需要的是一个Context ......对于静态方法这可能意味着你需要时调用它们沿着上下文来传递。

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.