<legend id='pvSND'><style id='pvSND'><dir id='pvSND'><q id='pvSND'></q></dir></style></legend>

    <small id='pvSND'></small><noframes id='pvSND'>

    <tfoot id='pvSND'></tfoot>

        <i id='pvSND'><tr id='pvSND'><dt id='pvSND'><q id='pvSND'><span id='pvSND'><b id='pvSND'><form id='pvSND'><ins id='pvSND'></ins><ul id='pvSND'></ul><sub id='pvSND'></sub></form><legend id='pvSND'></legend><bdo id='pvSND'><pre id='pvSND'><center id='pvSND'></center></pre></bdo></b><th id='pvSND'></th></span></q></dt></tr></i><div id='pvSND'><tfoot id='pvSND'></tfoot><dl id='pvSND'><fieldset id='pvSND'></fieldset></dl></div>
          <bdo id='pvSND'></bdo><ul id='pvSND'></ul>

        单个 ListView 内的多个 ViewPagers 崩溃

        时间:2023-10-03

              <tbody id='4iBE2'></tbody>
            <tfoot id='4iBE2'></tfoot>

            <small id='4iBE2'></small><noframes id='4iBE2'>

              <bdo id='4iBE2'></bdo><ul id='4iBE2'></ul>

                  <legend id='4iBE2'><style id='4iBE2'><dir id='4iBE2'><q id='4iBE2'></q></dir></style></legend>
                1. <i id='4iBE2'><tr id='4iBE2'><dt id='4iBE2'><q id='4iBE2'><span id='4iBE2'><b id='4iBE2'><form id='4iBE2'><ins id='4iBE2'></ins><ul id='4iBE2'></ul><sub id='4iBE2'></sub></form><legend id='4iBE2'></legend><bdo id='4iBE2'><pre id='4iBE2'><center id='4iBE2'></center></pre></bdo></b><th id='4iBE2'></th></span></q></dt></tr></i><div id='4iBE2'><tfoot id='4iBE2'></tfoot><dl id='4iBE2'><fieldset id='4iBE2'></fieldset></dl></div>

                2. 本文介绍了单个 ListView 内的多个 ViewPagers 崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  当通过 Viewpagers 滑动时,它的工作完美,我在 getView() 方法上使用 ViewPagerssetId() 方法完成了>BaseAdapter.

                  When Swipe through Viewpagers its Working Perfectly which i had done using setId() method for ViewPagers on getView() method of BaseAdapter.

                  实现代码类似于这个线程,我在这里找到:在这篇文章中

                  Code Of Implementation is similar to this thread, which i found here: On This Post

                  在创建每个 ViewPager 的 Object 后添加 setId(position+1).

                  Just added setId(position+1) after creating each ViewPager's Object.

                  但是当我开始滚动列表(水平)时,应用程序崩溃,显示以下 Logcat 中的错误:

                  06-18 21:06:55.020: E/AndroidRuntime(1928): 致命异常: main06-18 21:06:55.020: E/AndroidRuntime(1928):android.content.res.Resources$NotFoundException:找不到资源 ID #0x7 06-18 21:06:55.020: E/AndroidRuntime(1928): atandroid.content.res.Resources.getResourceName(Resources.java:1653)06-18 21:06:55.020: E/AndroidRuntime(1928): 在android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:903)06-18 21:06:55.020: E/AndroidRuntime(1928): 在android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088)06-18 21:06:55.020: E/AndroidRuntime(1928): 在android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)06-18 21:06:55.020: E/AndroidRuntime(1928): 在android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444)06-18 21:06:55.020: E/AndroidRuntime(1928): 在android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:461)06-18 21:06:55.020: E/AndroidRuntime(1928): 在android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141) 06-18 21:06:55.020: E/AndroidRuntime(1928): atandroid.support.v4.view.ViewPager.populate(ViewPager.java:1064) 06-1821:06:55.020:E/AndroidRuntime(1928):在android.support.v4.view.ViewPager.populate(ViewPager.java:911) 06-1821:06:55.020:E/AndroidRuntime(1928):在android.support.v4.view.ViewPager.setAdapter(ViewPager.java:440) 06-1821:06:55.020:E/AndroidRuntime(1928):在com.example.democardswipelistview.CustomSwipeAdapter.getView(CustomSwipeAdapter.java:72)06-18 21:06:55.020: E/AndroidRuntime(1928): 在android.widget.AbsListView.obtainView(AbsListView.java:2012) 06-1821:06:55.020:E/AndroidRuntime(1928):在android.widget.ListView.makeAndAddView(ListView.java:1772) 06-1821:06:55.020:E/AndroidRuntime(1928):在android.widget.ListView.fillUp(ListView.java:705) 06-18 21:06:55.020:E/AndroidRuntime(1928):在android.widget.ListView.fillGap(ListView.java:645) 06-18 21:06:55.020:E/AndroidRuntime(1928):在android.widget.AbsListView.trackMotionScroll(AbsListView.java:4546)06-18 21:06:55.020: E/AndroidRuntime(1928): 在android.widget.AbsListView$FlingRunnable.run(AbsListView.java:3813)06-18 21:06:55.020: E/AndroidRuntime(1928): 在android.os.Handler.handleCallback(Handler.java:605) 06-1821:06:55.020:E/AndroidRuntime(1928):在android.os.Handler.dispatchMessage(Handler.java:92) 06-1821:06:55.020:E/AndroidRuntime(1928):在android.os.Looper.loop(Looper.java:137) 06-18 21:06:55.020:E/AndroidRuntime(1928):在android.app.ActivityThread.main(ActivityThread.java:4424) 06-1821:06:55.020:E/AndroidRuntime(1928):在java.lang.reflect.Method.invokeNative(Native Method) 06-1821:06:55.020:E/AndroidRuntime(1928):在java.lang.reflect.Method.invoke(Method.java:511) 06-18 21:06:55.020:E/AndroidRuntime(1928):在com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)06-18 21:06:55.020: E/AndroidRuntime(1928): 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 06-1821:06:55.020:E/AndroidRuntime(1928):在dalvik.system.NativeStart.main(Native Method)

                  06-18 21:06:55.020: E/AndroidRuntime(1928): FATAL EXCEPTION: main 06-18 21:06:55.020: E/AndroidRuntime(1928): android.content.res.Resources$NotFoundException: Unable to find resource ID #0x7 06-18 21:06:55.020: E/AndroidRuntime(1928): at android.content.res.Resources.getResourceName(Resources.java:1653) 06-18 21:06:55.020: E/AndroidRuntime(1928): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:903) 06-18 21:06:55.020: E/AndroidRuntime(1928): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1088) 06-18 21:06:55.020: E/AndroidRuntime(1928): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682) 06-18 21:06:55.020: E/AndroidRuntime(1928): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1444) 06-18 21:06:55.020: E/AndroidRuntime(1928): at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:461) 06-18 21:06:55.020: E/AndroidRuntime(1928): at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141) 06-18 21:06:55.020: E/AndroidRuntime(1928): atandroid.support.v4.view.ViewPager.populate(ViewPager.java:1064) 06-18 21:06:55.020: E/AndroidRuntime(1928): at android.support.v4.view.ViewPager.populate(ViewPager.java:911) 06-18 21:06:55.020: E/AndroidRuntime(1928): at android.support.v4.view.ViewPager.setAdapter(ViewPager.java:440) 06-18 21:06:55.020: E/AndroidRuntime(1928): at com.example.democardswipelistview.CustomSwipeAdapter.getView(CustomSwipeAdapter.java:72) 06-18 21:06:55.020: E/AndroidRuntime(1928): at android.widget.AbsListView.obtainView(AbsListView.java:2012) 06-18 21:06:55.020: E/AndroidRuntime(1928): at android.widget.ListView.makeAndAddView(ListView.java:1772) 06-18 21:06:55.020: E/AndroidRuntime(1928): at android.widget.ListView.fillUp(ListView.java:705) 06-18 21:06:55.020: E/AndroidRuntime(1928): at android.widget.ListView.fillGap(ListView.java:645) 06-18 21:06:55.020: E/AndroidRuntime(1928): at android.widget.AbsListView.trackMotionScroll(AbsListView.java:4546) 06-18 21:06:55.020: E/AndroidRuntime(1928): at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:3813) 06-18 21:06:55.020: E/AndroidRuntime(1928): at android.os.Handler.handleCallback(Handler.java:605) 06-18 21:06:55.020: E/AndroidRuntime(1928): at android.os.Handler.dispatchMessage(Handler.java:92) 06-18 21:06:55.020: E/AndroidRuntime(1928): at android.os.Looper.loop(Looper.java:137) 06-18 21:06:55.020: E/AndroidRuntime(1928): at android.app.ActivityThread.main(ActivityThread.java:4424) 06-18 21:06:55.020: E/AndroidRuntime(1928): at java.lang.reflect.Method.invokeNative(Native Method) 06-18 21:06:55.020: E/AndroidRuntime(1928): at java.lang.reflect.Method.invoke(Method.java:511) 06-18 21:06:55.020: E/AndroidRuntime(1928): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) 06-18 21:06:55.020: E/AndroidRuntime(1928): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 06-18 21:06:55.020: E/AndroidRuntime(1928): at dalvik.system.NativeStart.main(Native Method)

                  推荐答案

                  好的,2天后,我能够解决类似的问题.

                  Ok so after 2 days, I was able to solve a similar issue like this.

                  首先不要在 getView() 中持久化你的 ViewPager.我的意思是你不应该调用 convertView.setTag(holder);holder = (ViewHolder)convertView.getTag().只需删除检查 convertView 是否为空的 if 语句.然后完全删除 else 语句块.

                  First do not persist your ViewPager in the getView(). What I mean by this is that you shouldn't call convertView.setTag(holder); or holder = (ViewHolder)convertView.getTag(). Just remove the if statement that checks if convertView is null. Then completely remove the else statement block.

                  要进行的另一项更改(这不是原因之一)是您需要优化设置 ID 的方式.而不是 setId(position+1),在你的 values 文件夹中创建一个 Ids.xml 文件,然后在该文件中,放入:

                  Another change to make (this is not one of the causes) is you need to optimize the way you set the Ids. Instead of setId(position+1), make an Ids.xml file in your values folder, then inside that file, put this:

                  <?xml version="1.0" encoding="utf-8"?>
                  
                  <resources>
                    <!-- use to generate non-conflicting ids for the viewpager -->
                  
                    <item name="viewpager_id_base" type="id"/>
                  </resources>
                  

                  然后在您的 getView() 方法中将 setId(position+1) 替换为 setId(R.id.viewpager_id_base + position)

                  Then in your getView() method replace setId(position+1) with setId(R.id.viewpager_id_base + position)

                  经过上述更改后,列表不会崩溃,但在您将项目滚动到屏幕后它会消失.这是解决方法:

                  After the above change, the list will not crash, but it will disappear after you scroll the item off screen. Here is the fix for that:

                  确保您的自定义 PageAdapter 扩展了 FragmentStatePagerAdapter,而不是 FragmentPagerAdapter.这将正确销毁视图并触发 onCreateView().

                  Make sure your Custom PageAdapter extends FragmentStatePagerAdapter, not FragmentPagerAdapter. This will properly destroy the views and trigger the onCreateView().

                  这篇关于单个 ListView 内的多个 ViewPagers 崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:E/Web 控制台(8272):未捕获的 ReferenceError:未定义函数名称:1 在视图寻呼机中加载 web 下一篇:获取不同片段上的 EditText 值

                  相关文章

                  • <bdo id='2BSUU'></bdo><ul id='2BSUU'></ul>
                  <i id='2BSUU'><tr id='2BSUU'><dt id='2BSUU'><q id='2BSUU'><span id='2BSUU'><b id='2BSUU'><form id='2BSUU'><ins id='2BSUU'></ins><ul id='2BSUU'></ul><sub id='2BSUU'></sub></form><legend id='2BSUU'></legend><bdo id='2BSUU'><pre id='2BSUU'><center id='2BSUU'></center></pre></bdo></b><th id='2BSUU'></th></span></q></dt></tr></i><div id='2BSUU'><tfoot id='2BSUU'></tfoot><dl id='2BSUU'><fieldset id='2BSUU'></fieldset></dl></div>

                  1. <small id='2BSUU'></small><noframes id='2BSUU'>

                    <legend id='2BSUU'><style id='2BSUU'><dir id='2BSUU'><q id='2BSUU'></q></dir></style></legend>

                    <tfoot id='2BSUU'></tfoot>