本文整理匯總了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());
}
示例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;
}