android how to use string resource in a java class

后端 未结 4 1090
说谎
说谎 2020-12-29 20:04

In my java class I want to use a string resource from strings.xml.

for that I have to use like below,

getString(R.string.address)

i

4条回答
  •  佛祖请我去吃肉
    2020-12-29 20:12

    You can pass the context of the Activity class to the java class and access the resources.

    From your Activity Class

     Helper helper = new Helper(this);
    

    Your Java class

    public class Helper {
    
        Helper(Context c){
            c.getString(R.string.address);
        }
    }
    

提交回复
热议问题