How to get String Resource within ViewPager Adapter?

后端 未结 9 1875
孤城傲影
孤城傲影 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:30

    Well, according to your error message you do not have a String with the ID you are requesting.

    Could it be that you are supporting multi languages and only have this kind of String-ID for a specific language?

    Anyways, this line of code:

    String yourstring = getResources().getString(R.string.yourstring);
    

    is how to get a String from Resources. getResources() can be called whenever you are in a class extending Context, such as Activity.

提交回复
热议问题