在一个活动类中,我有这个类(来自 android 示例):
public static class DemoCollectionPagerAdapter extends FragmentStatePagerAdapter {
public DemoCollectionPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int i) {
Fragment fragment = new QuestionFragment();
Bundle args = new Bundle();
args.putInt(QuestionFragment.ARG_OBJECT, i );
fragment.setArguments(args);
return fragment;
}
@Override
public int getCount() {
return questionList.length;
}
@Override
public CharSequence getPageTitle(int position) {
return "Title n°" + (position + 1);
}
}
我想改变这个:return "Title n°" + (position + 1); to: return getActivity().getResources().getString(R.string.questionTabTitle) + (position + 1);
但是活动是未定义的。我怎样才能得到我需要的字符串资源?