Access to getString() in a fragment that implements a viewpager

烂漫一生 提交于 2019-12-05 07:04:18

You can pass the Activity to your adapter constructor.

mViewPager.setAdapter(new MyAdapter (getChildFragmentManager(), getActivity()));

then in MyAdapter:

//declare a private variable for the activity
private Activity myActivity;
public MyAdapter(FragmentManager fm, Activity myActivity) {
    super(fm);
    this.myActivity = myActivity;
}

then in your getPageTitle

...
return myActivity.getString(R.String.title_section_scheduale1).toUpperCase(l);
...

Try it out hope it works for you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!