use*_*413 6 android getstring android-context
我使用它getString()从string.xml成为String.在我的班级(非活动)不起作用:
如何获取此类的String?
public class myClass{
public String[] myInfo(String ID) {
String myString = getRessources().getString(R.string.myString);
};
}
Run Code Online (Sandbox Code Playgroud)
Ahm*_*mad 14
你必须打电话context.getResources().getString(),但你必须传入一个上下文才能做到这一点.
您可以创建一个构造函数,例如:
Context context;
public myClass(Context context) {
this.context = context;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9135 次 |
| 最近记录: |