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

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

  • <legend id='T9mWs'><style id='T9mWs'><dir id='T9mWs'><q id='T9mWs'></q></dir></style></legend>
      <bdo id='T9mWs'></bdo><ul id='T9mWs'></ul>

      1. <tfoot id='T9mWs'></tfoot>

        如何强制 ViewPager 重新实例化其项目

        时间:2023-10-04

        1. <tfoot id='NfTkW'></tfoot>
            <tbody id='NfTkW'></tbody>

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

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

              • <bdo id='NfTkW'></bdo><ul id='NfTkW'></ul>
                <legend id='NfTkW'><style id='NfTkW'><dir id='NfTkW'><q id='NfTkW'></q></dir></style></legend>
                • 本文介绍了如何强制 ViewPager 重新实例化其项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 ViewPager 允许用户在其视图之间滑动.有没有办法强制此 ViewPager 重新加载/重新实例化其视图,以防它们不再有效或需要刷新?我试图在其适配器上调用 notifyDataSetChanged() 但这不会再次调用 instantiateItem() 方法.

                  I am using ViewPager to allow user to swipe between its views. Is there a way how to force this ViewPager to reload/re-instantiate its views in case that they are no longer valid or needs to be refreshed? I tried to call notifyDataSetChanged() on its adapter but this does not invoke instantiateItem() method again.

                  这是从 ViewPager 及其适配器定义扩展而来的类.Bellow 是我想强制刷新项目时调用的 refresh() 方法.

                  Here is the class that extends from ViewPager and its adapter definision. Bellow is the refresh() method that I call when I want to force to refresh items.

                  public class DayFlipper extends ViewPager {
                  
                  public class FlipperAdapter extends PagerAdapter {
                  
                      @Override
                      public int getCount() {
                          return DayFlipper.DAY_HISTORY;
                      }
                  
                      @Override
                      public void startUpdate(View container) {
                      }
                  
                      @Override
                      public Object instantiateItem(View container, int position) {
                          Log.d(TAG, "instantiateItem(): " + position);
                  
                          Date d = DateHelper.getBot();
                          for (int i = 0; i < position; i++) {
                              d = DateHelper.getTomorrow(d);
                          }
                  
                          d = DateHelper.normalize(d);
                  
                          CubbiesView cv = new CubbiesView(mContext);
                          cv.setLifeDate(d);
                          ((ViewPager) container).addView(cv, 0);
                          // add map
                          cv.setCubbieMap(mMap);
                          cv.initEntries(d);
                          return cv;
                      }
                  
                      @Override
                      public void destroyItem(View container, int position, Object object) {
                          ((ViewPager) container).removeView((CubbiesView) object);
                      }
                  
                      @Override
                      public void finishUpdate(View container) {
                  
                      }
                  
                      @Override
                      public boolean isViewFromObject(View view, Object object) {
                          return view == ((CubbiesView) object);
                      }
                  
                      @Override
                      public Parcelable saveState() {
                          return null;
                      }
                  
                      @Override
                      public void restoreState(Parcelable state, ClassLoader loader) {
                  
                      }
                  
                  }
                  
                      ...
                  
                      public void refresh() {
                      getAdapter().notifyDataSetChanged();
                  }
                  }
                  

                  推荐答案

                  我找到了解决方案.这只是我的问题的一种解决方法,但目前是唯一的解决方案.

                  I have found a solution. It is just a workaround to my problem but currently the only solution.

                  ViewPager PagerAdapter 不更新视图

                  public int getItemPosition(Object object) {
                     return POSITION_NONE;
                  }
                  

                  有人知道这是否是一个错误吗?

                  Does anyone know whether this is a bug or not?

                  这篇关于如何强制 ViewPager 重新实例化其项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:ScrollView 中的 ViewPager 无法正确滚动 下一篇:android: 如何从 Android Support Lib 版本 4 向 PagerTabStrip 添加图标/d

                  相关文章

                • <legend id='IYfVI'><style id='IYfVI'><dir id='IYfVI'><q id='IYfVI'></q></dir></style></legend>

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

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

                    <bdo id='IYfVI'></bdo><ul id='IYfVI'></ul>