我的应用中有一个sectionpager
,想要从字符串资源加载其标题,以支持不同的语言标题。
这是我的sectionpager
课程:
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
Auftrag fragmenttab1 = new Auftrag();
return fragmenttab1;
case 1:
Email fragmenttab2 = new Email();
return fragmenttab2;
case 2:
Fragen fragmenttab3 = new Fragen();
return fragmenttab3;
case 3:
Statistik fragmenttab4 = new Statistik();
return fragmenttab4;
}
return null;
}
@Override
public int getCount() {
return 4;
}
@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
return Resources.getSystem().getString(R.string.questions);
case 1:
return Resources.getSystem().getString(R.string.emails);
case 2:
return Resources.getSystem().getString(R.string.calls);
case 3:
return Resources.getSystem().getString(R.string.orders);
}
return null;
}
}
这是我得到的错误:
06-11 09:44:07.110: E/AndroidRuntime(18290): FATAL EXCEPTION: main
06-11 09:44:07.110: E/AndroidRuntime(18290):
android.content.res.Resources$NotFoundException: String resource ID #0x7f040024
06-11 09:44:07.110: E/AndroidRuntime(18290): at
android.content.res.Resources.getText(Resources.java:1068)
06-11 09:44:07.110: E/AndroidRuntime(18290): at
android.content.res.Resources.getString(Resources.java:1162)
06-11 09:44:07.110: E/AndroidRuntime(18290): at
com.myappp.sectionapp.SectionsPagerAdapter.getPageTitle(SectionsPagerAdapter.java:41)
06-11 09:44:07.110: E/AndroidRuntime(18290): at
android.support.v4.view.PagerTitleStrip.updateText(PagerTitleStrip.java:280)
06-11 09:44:07.110: E/AndroidRuntime(18290): at
android.support.v4.view.PagerTitleStrip.updateAdapter(PagerTitleStrip.java:327)
06-11 09:44:07.110: E/AndroidRuntime(18290): at
android.support.v4.view.PagerTitleStrip.onAttachedToWindow(PagerTitleStrip.java:256)
06-11 09:44:07.110: E/AndroidRuntime(18290): at
android.view.View.dispatchAttachedToWindow(View.java:13029)
06-11 09:44:07.110: E/AndroidRuntime(18290): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2683)
06-11 09:44:07.110: E/AndroidRuntime(18290): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2690)
06-11 09:44:07.110: E/AndroidRuntime(18290): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2690)
06-11 09:44:07.110: E/AndroidRuntime(18290): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2690)
06-11 09:44:07.110: E/AndroidRuntime(18290): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2690)
06-11 09:44:07.110: E/AndroidRuntime(18290): at
android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2690)
06-11 09:44:07.110: E/AndroidRuntime(18290): at
android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1457)
06-11 09:44:07.110: E/AndroidRuntime(18290): at
android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1249)
06-11 09:44:07.110: E/AndroidRuntime(18290): at
android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6364)
06-11 09:44:07.110: E/AndroidRuntime(18290): at
android.view.Choreographer$CallbackRecord.run(Choreographer.java:791)
06-11 09:44:07.110: E/AndroidRuntime(18290): at
android.view.Choreographer.doCallbacks(Choreographer.java:591)
06-11 09:44:07.110: E/AndroidRuntime(18290): at
android.view.Choreographer.doFrame(Choreographer.java:561)
06-11 09:44:07.110: E/AndroidRuntime(18290): at
android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:777)
06-11 09:44:07.110: E/AndroidRuntime(18290): at
android.os.Handler.handleCallback(Handler.java:730)
06-11 09:44:07.110: E/AndroidRuntime(18290): at
android.os.Handler.dispatchMessage(Handler.java:92)
06-11 09:44:07.110: E/AndroidRuntime(18290): at
android.os.Looper.loop(Looper.java:176)
06-11 09:44:07.110: E/AndroidRuntime(18290): at
android.app.ActivityThread.main(ActivityThread.java:5419)
06-11 09:44:07.110: E/AndroidRuntime(18290): at
java.lang.reflect.Method.invokeNative(Native Method)
06-11 09:44:07.110: E/AndroidRuntime(18290): at
java.lang.reflect.Method.invoke(Method.java:525)
06-11 09:44:07.110: E/AndroidRuntime(18290): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
06-11 09:44:07.110: E/AndroidRuntime(18290): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
06-11 09:44:07.110: E/AndroidRuntime(18290): at
dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)