Access to getString() in android.support.v4.app.FragmentPagerAdapter?

后端 未结 3 905
既然无缘
既然无缘 2020-12-10 06:23

In a class extending android.support.v4.app.FragmentPagerAdapter, is there any way to get access to the Context.getString(..) method without the ex

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-10 06:44

    From an Activity, use:

    this.getString(R.string.string_name);
    

    From a Fragment, use:

    getActivity.getString(R.string.string_name);
    

    From an adapter, use:

    getContext().getResources().getString(R.string.string_name);
    

提交回复
热议问题