How to get String Resource within ViewPager Adapter?

后端 未结 9 1874
孤城傲影
孤城傲影 2020-12-31 07:42

I trying to set the title for my viewpager, I can\'t seem to get it to work. I tried Resources.getSystem().getString(R.string.title1); and also tried to pass a context. Coul

9条回答
  •  情话喂你
    2020-12-31 08:47

    If you are trying to access string resources from outside of an activity, then you need to pass the context in to that class (which you stated you have already done), and then call

    String str = context.getResources().getString(R.string.some_string);
    

    Also check your strings.xml file to make sure that you are using the string id correctly. If you're using android studio you should be able to simply start typing R.string. and it will then show suggestions from the strings.xml file. If you do not see your resource here, then that may indicate a problem with the way you are storing your resources, as opposed to how you are trying to access them.

提交回复
热议问题