当前位置: 首页>>代码示例>>Java>>正文


Java ViewPager.addOnAdapterChangeListener方法代码示例

本文整理汇总了Java中android.support.v4.view.ViewPager.addOnAdapterChangeListener方法的典型用法代码示例。如果您正苦于以下问题:Java ViewPager.addOnAdapterChangeListener方法的具体用法?Java ViewPager.addOnAdapterChangeListener怎么用?Java ViewPager.addOnAdapterChangeListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.v4.view.ViewPager的用法示例。


在下文中一共展示了ViewPager.addOnAdapterChangeListener方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setViewPager

import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
public void setViewPager(ViewPager viewPager) {
    if (viewPager == null) {
        tabsContainer.removeAllViews();
        if (this.viewPager != null) {
            this.viewPager.removeOnAdapterChangeListener(adapterChangeListener);
            this.viewPager.removeOnPageChangeListener(this);
        }
        this.viewPager = viewPager;
        return;
    }
    this.viewPager = viewPager;
    this.viewPager.addOnPageChangeListener(this);
    adapterChangeListener = new ViewPager.OnAdapterChangeListener() {
        @Override
        public void onAdapterChanged(@NonNull ViewPager viewPager, @Nullable PagerAdapter oldAdapter, @Nullable PagerAdapter newAdapter) {
            listenToAdapterChanges(newAdapter);
        }
    };
    viewPager.addOnAdapterChangeListener(adapterChangeListener);

    listenToAdapterChanges(viewPager.getAdapter());
}
 
开发者ID:Crysis21,项目名称:PagerTabIndicator,代码行数:23,代码来源:PagerTabsIndicator.java

示例2: setupWithViewPager

import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
private void setupWithViewPager(@Nullable final ViewPager viewPager, boolean autoRefresh,
          boolean implicitSetup) {
  if (mViewPager != null) {
    // If we've already been setup with a ViewPager, remove us from it
    if (mPageChangeListener != null) {
      mViewPager.removeOnPageChangeListener(mPageChangeListener);
    }
    if (mAdapterChangeListener != null) {
      mViewPager.removeOnAdapterChangeListener(mAdapterChangeListener);
    }
  }

  if (mCurrentVpSelectedListener != null) {
    // If we already have a tab selected listener for the ViewPager, remove it
    removeOnTabSelectedListener(mCurrentVpSelectedListener);
    mCurrentVpSelectedListener = null;
  }

  if (viewPager != null) {
    mViewPager = viewPager;

    // Add our custom OnPageChangeListener to the ViewPager
    if (mPageChangeListener == null) {
      mPageChangeListener = new TabLayoutOnPageChangeListener(this);
    }
    mPageChangeListener.reset();
    viewPager.addOnPageChangeListener(mPageChangeListener);

    // Now we'll add a tab selected listener to set ViewPager's current item
    mCurrentVpSelectedListener = new ViewPagerOnTabSelectedListener(viewPager);
    addOnTabSelectedListener(mCurrentVpSelectedListener);

    final PagerAdapter adapter = viewPager.getAdapter();
    if (adapter != null) {
      // Now we'll populate ourselves from the pager adapter, adding an observer if
      // autoRefresh is enabled
      setPagerAdapter(adapter, autoRefresh);
    }

    // Add a listener so that we're notified of any adapter changes
    if (mAdapterChangeListener == null) {
      mAdapterChangeListener = new AdapterChangeListener();
    }
    mAdapterChangeListener.setAutoRefresh(autoRefresh);
    viewPager.addOnAdapterChangeListener(mAdapterChangeListener);

    // Now update the scroll position to match the ViewPager's current item
    setScrollPosition(viewPager.getCurrentItem(), 0f, true);
  } else {
    // We've been given a null ViewPager so we need to clear out the internal state,
    // listeners and observers
    mViewPager = null;
    setPagerAdapter(null, false);
  }

  mSetupViewPagerImplicitly = implicitSetup;
}
 
开发者ID:commonsguy,项目名称:cwac-crossport,代码行数:58,代码来源:TabLayout.java


注:本文中的android.support.v4.view.ViewPager.addOnAdapterChangeListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。