viewpager嵌套问题

常常鲜 发布于 2014/03/27 22:34
阅读 4K+
收藏 0

一个Activity中加以个viewpager 管理多个 fragment  在fragment中在嵌套一个viewpager 可以吗· 我现在嵌套进去报异常

03-27 14:14:52.188: E/AndroidRuntime(1632): FATAL EXCEPTION: main
03-27 14:14:52.188: E/AndroidRuntime(1632): java.lang.UnsupportedOperationException: Required method instantiateItem was not overridden
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.support.v4.view.PagerAdapter.instantiateItem(PagerAdapter.java:175)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.support.v4.view.PagerAdapter.instantiateItem(PagerAdapter.java:110)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:832)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.support.v4.view.ViewPager.populate(ViewPager.java:982)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.support.v4.view.ViewPager.populate(ViewPager.java:914)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1436)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.view.View.measure(View.java:15172)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.widget.LinearLayout.measureVertical(LinearLayout.java:833)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.view.View.measure(View.java:15172)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1038)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.widget.LinearLayout.onMeasure(LinearLayout.java:576)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.view.View.measure(View.java:15172)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.view.View.measure(View.java:15172)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.view.View.measure(View.java:15172)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.view.View.measure(View.java:15172)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.view.View.measure(View.java:15172)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1038)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.widget.LinearLayout.onMeasure(LinearLayout.java:576)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.view.View.measure(View.java:15172)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.widget.HorizontalScrollView.measureChildWithMargins(HorizontalScrollView.java:1216)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.widget.HorizontalScrollView.onMeasure(HorizontalScrollView.java:299)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.view.View.measure(View.java:15172)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.view.View.measure(View.java:15172)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.view.View.measure(View.java:15172)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.widget.LinearLayout.measureVertical(LinearLayout.java:833)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.view.View.measure(View.java:15172)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
03-27 14:14:52.188: E/AndroidRuntime(1632): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2148)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.view.View.measure(View.java:15172)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1848)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1100)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1273)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:998)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4212)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.view.Choreographer.doCallbacks(Choreographer.java:555)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.view.Choreographer.doFrame(Choreographer.java:525)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.os.Handler.handleCallback(Handler.java:615)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.os.Handler.dispatchMessage(Handler.java:92)
03-27 14:14:52.188: E/AndroidRuntime(1632): at android.os.


加载中
0
w
w_xiaolong
Required method instantiateItem was not overridden        意思就是你的adapter没有重写 instantiateItem ,就是那个初始化view的方法 ,我估计是你fragment里面的viewpager的adapter没写全
0
陪伴zhe你
陪伴zhe你

把instantiateItem方法中的return super.instantiateItem(container, position);

换成:

return container;试试看

返回顶部
顶部