我试图为我的查看器设置标题,我似乎无法让它工作。我试过 Resources.getSystem().getString(R.string.title1); 并且还试图传递一个上下文。有人可以帮我吗?
public class ViewPagerAdapter extends FragmentPagerAdapter {
final int PAGE_COUNT = 3;
Context context;
public ViewPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public int getCount() {
return PAGE_COUNT;
}
@Override
public Fragment getItem(int position) {
return PageFragment.create(position + 1);
}
@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
return Resources.getSystem().getString(R.string.title1);
case 1:
return Resources.getSystem().getString(R.string.title1);
case 2:
return Resources.getSystem().getString(R.string.title1);
}
return null;
}
}
日志猫:
09-02 17:40:33.160: E/AndroidRuntime(3116): FATAL EXCEPTION: main
09-02 17:40:33.160: E/AndroidRuntime(3116): android.content.res.Resources$NotFoundException: String resource ID #0x7f050003
09-02 17:40:33.160: E/AndroidRuntime(3116): at android.content.res.Resources.getText(Resources.java:230)
09-02 17:40:33.160: E/AndroidRuntime(3116): at android.content.res.Resources.getString(Resources.java:314)