Java Code Examples for androidx.viewpager.widget.ViewPager#setOnPageChangeListener()

The following examples show how to use androidx.viewpager.widget.ViewPager#setOnPageChangeListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VisualViewPagerActivity.java    From ans-android-sdk with GNU General Public License v3.0 6 votes vote down vote up
/**
     * 初始化ViewPager
     */
    private void InitViewPager() {
        mPager = (ViewPager) findViewById(R.id.vPager);
        listViews = new ArrayList<Fragment>();
/*	LayoutInflater mInflater = getLayoutInflater();
    listViews.add(mInflater.inflate(R.layout.activity_visual_viewpager_one, null));
	listViews.add(mInflater.inflate(R.layout.activity_visual_viewpager_two, null));
	listViews.add(mInflater.inflate(R.layout.activity_visual_viewpager_three, null));*/
        listViews.add(oneFragment);
        listViews.add(twoFragment);
        listViews.add(thrFragment);
        //用support包,只能用getSupportFragmentManager();
        FragmentManager fragmentManager = this.getSupportFragmentManager();
        //通过fragment适配器把fragment添加入viewpager中
        mPager.setAdapter(new VisualViewPagerAdapter(fragmentManager, listViews));
        mPager.setCurrentItem(0);
        mPager.setOnPageChangeListener(new MyOnPageChangeListener());
    }
 
Example 2
Source File: IconPageIndicator.java    From arcusandroid with Apache License 2.0 6 votes vote down vote up
@Override
public void setViewPager(ViewPager view) {
    if (mViewPager == view) {
        return;
    }
    if (mViewPager != null) {
        mViewPager.setOnPageChangeListener(null);
    }
    PagerAdapter adapter = view.getAdapter();
    if (adapter == null) {
        throw new IllegalStateException("ViewPager does not have adapter instance.");
    }
    mViewPager = view;
    view.setOnPageChangeListener(this);
    notifyDataSetChanged();
}
 
Example 3
Source File: TabPageIndicator.java    From arcusandroid with Apache License 2.0 6 votes vote down vote up
@Override
public void setViewPager(ViewPager view) {
    if (mViewPager == view) {
        return;
    }
    if (mViewPager != null) {
        mViewPager.setOnPageChangeListener(null);
    }
    final PagerAdapter adapter = view.getAdapter();
    if (adapter == null) {
        throw new IllegalStateException("ViewPager does not have adapter instance.");
    }
    mViewPager = view;
    view.setOnPageChangeListener(this);
    notifyDataSetChanged();
}
 
Example 4
Source File: SlidingTabLayout.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the associated view pager. Note that the assumption here is that the pager content
 * (number of tabs and tab titles) does not change after this call has been made.
 */
public void setViewPager(@Nullable ViewPager viewPager) {
    mTabStrip.removeAllViews();

    mViewPager = viewPager;
    if (viewPager != null) {
        viewPager.setOnPageChangeListener(new InternalViewPagerListener());
        populateTabStrip();
    }
}
 
Example 5
Source File: PagerSlidingTabStrip.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
public void setViewPager(@NonNull ViewPager pager) {
    this.pager = pager;

    if (pager.getAdapter() == null) {
        throw new IllegalStateException("ViewPager does not have adapter instance.");
    }

    pager.setOnPageChangeListener(pageListener);

    notifyDataSetChanged();
}
 
Example 6
Source File: PagerSlidingTabStrip.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
public void setViewPager(@NonNull ViewPager pager) {
    this.pager = pager;

    if (pager.getAdapter() == null) {
        throw new IllegalStateException("ViewPager does not have adapter instance.");
    }

    pager.setOnPageChangeListener(pageListener);

    notifyDataSetChanged();
}
 
Example 7
Source File: SlidingTabLayout.java    From UltimateRecyclerView with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the associated view pager. Note that the assumption here is that the pager content
 * (number of tabs and tab titles) does not change after this call has been made.
 */
public void setViewPager(ViewPager viewPager) {
    mTabStrip.removeAllViews();

    mViewPager = viewPager;
    if (viewPager != null) {
        viewPager.setOnPageChangeListener(new InternalViewPagerListener());
        populateTabStrip();
    }
}
 
Example 8
Source File: SlidingTabLayout.java    From android-test with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the associated view pager. Note that the assumption here is that the pager content (number
 * of tabs and tab titles) does not change after this call has been made.
 */
public void setViewPager(ViewPager viewPager) {
  mTabStrip.removeAllViews();

  mViewPager = viewPager;
  if (viewPager != null) {
    viewPager.setOnPageChangeListener(new InternalViewPagerListener());
    populateTabStrip();
  }
}
 
Example 9
Source File: Slideable.java    From FragmentMaster with Apache License 2.0 5 votes vote down vote up
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    ViewPager viewPager = (ViewPager) view.findViewById(R.id.view_pager);
    viewPager.setAdapter(new Adapter());
    viewPager.setOnPageChangeListener(this);
}
 
Example 10
Source File: PagerSlidingTabStrip.java    From light-novel-library_Wenku8_Android with GNU General Public License v2.0 5 votes vote down vote up
public void setViewPager(ViewPager pager) {
    this.pager = pager;
    if (pager.getAdapter() == null) {
        throw new IllegalStateException("ViewPager does not have adapter instance.");
    }

    pager.setOnPageChangeListener(pageListener);
    pager.getAdapter().registerDataSetObserver(adapterObserver);
    adapterObserver.setAttached(true);
    notifyDataSetChanged();
}
 
Example 11
Source File: PagerSlidingTabStrip.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public void setViewPager(ViewPager pager) {
    this.pager = pager;
    if (pager.getAdapter() == null) {
        throw new IllegalStateException("ViewPager does not have adapter instance.");
    }
    pager.setOnPageChangeListener(pageListener);
    notifyDataSetChanged();
}
 
Example 12
Source File: PagerSlidingTabStrip.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public void setViewPager(ViewPager pager) {
    this.pager = pager;
    if (pager.getAdapter() == null) {
        throw new IllegalStateException("ViewPager does not have adapter instance.");
    }
    pager.setOnPageChangeListener(pageListener);
    notifyDataSetChanged();
}
 
Example 13
Source File: DeviceDetailPagerAdapter.java    From arcusandroid with Apache License 2.0 4 votes vote down vote up
public void setUpPageListener(@NonNull final ViewPager viewPager) {
    CircularViewPagerHandler circularViewPagerHandler = new CircularViewPagerHandler(viewPager);
    viewPager.setOnPageChangeListener(circularViewPagerHandler);
}
 
Example 14
Source File: EmojiPalettesView.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 4 votes vote down vote up
@Override
protected void onFinishInflate() {
    mTabHost = (TabHost)findViewById(R.id.emoji_category_tabhost);
    mTabHost.setup();
    for (final EmojiCategory.CategoryProperties properties
            : mEmojiCategory.getShownCategories()) {
        addTab(mTabHost, properties.mCategoryId);
    }
    mTabHost.setOnTabChangedListener(this);
    final TabWidget tabWidget = mTabHost.getTabWidget();
    tabWidget.setStripEnabled(mCategoryIndicatorEnabled);
    if (mCategoryIndicatorEnabled) {
        // On TabWidget's strip, what looks like an indicator is actually a background.
        // And what looks like a background are actually left and right drawables.
        tabWidget.setBackgroundResource(mCategoryIndicatorDrawableResId);
        tabWidget.setLeftStripDrawable(mCategoryIndicatorBackgroundResId);
        tabWidget.setRightStripDrawable(mCategoryIndicatorBackgroundResId);
    }

    mEmojiPalettesAdapter = new EmojiPalettesAdapter(mEmojiCategory, this);

    mEmojiPager = (ViewPager)findViewById(R.id.emoji_keyboard_pager);
    mEmojiPager.setAdapter(mEmojiPalettesAdapter);
    mEmojiPager.setOnPageChangeListener(this);
    mEmojiPager.setOffscreenPageLimit(0);
    mEmojiPager.setPersistentDrawingCache(PERSISTENT_NO_CACHE);
    mEmojiLayoutParams.setPagerProperties(mEmojiPager);

    mEmojiCategoryPageIndicatorView =
            (EmojiCategoryPageIndicatorView)findViewById(R.id.emoji_category_page_id_view);
    mEmojiCategoryPageIndicatorView.setColors(
            mCategoryPageIndicatorColor, mCategoryPageIndicatorBackground);
    mEmojiLayoutParams.setCategoryPageIdViewProperties(mEmojiCategoryPageIndicatorView);

    setCurrentCategoryId(mEmojiCategory.getCurrentCategoryId(), true /* force */);

    final LinearLayout actionBar = (LinearLayout)findViewById(R.id.emoji_action_bar);
    mEmojiLayoutParams.setActionBarProperties(actionBar);

    // deleteKey depends only on OnTouchListener.
    mDeleteKey = (ImageButton)findViewById(R.id.emoji_keyboard_delete);
    mDeleteKey.setBackgroundResource(mFunctionalKeyBackgroundId);
    mDeleteKey.setTag(Constants.CODE_DELETE);
    mDeleteKey.setOnTouchListener(mDeleteKeyOnTouchListener);

    // {@link #mAlphabetKeyLeft}, {@link #mAlphabetKeyRight, and spaceKey depend on
    // {@link View.OnClickListener} as well as {@link View.OnTouchListener}.
    // {@link View.OnTouchListener} is used as the trigger of key-press, while
    // {@link View.OnClickListener} is used as the trigger of key-release which does not occur
    // if the event is canceled by moving off the finger from the view.
    // The text on alphabet keys are set at
    // {@link #startEmojiPalettes(String,int,float,Typeface)}.
    mAlphabetKeyLeft = (TextView)findViewById(R.id.emoji_keyboard_alphabet_left);
    mAlphabetKeyLeft.setBackgroundResource(mFunctionalKeyBackgroundId);
    mAlphabetKeyLeft.setTag(Constants.CODE_ALPHA_FROM_EMOJI);
    mAlphabetKeyLeft.setOnTouchListener(this);
    mAlphabetKeyLeft.setOnClickListener(this);
    mAlphabetKeyRight = (TextView)findViewById(R.id.emoji_keyboard_alphabet_right);
    mAlphabetKeyRight.setBackgroundResource(mFunctionalKeyBackgroundId);
    mAlphabetKeyRight.setTag(Constants.CODE_ALPHA_FROM_EMOJI);
    mAlphabetKeyRight.setOnTouchListener(this);
    mAlphabetKeyRight.setOnClickListener(this);
    mSpacebar = findViewById(R.id.emoji_keyboard_space);
    mSpacebar.setBackgroundResource(mSpacebarBackgroundId);
    mSpacebar.setTag(Constants.CODE_SPACE);
    mSpacebar.setOnTouchListener(this);
    mSpacebar.setOnClickListener(this);
    mEmojiLayoutParams.setKeyProperties(mSpacebar);
    mSpacebarIcon = findViewById(R.id.emoji_keyboard_space_icon);
}
 
Example 15
Source File: PageNumberSetter.java    From sketch with Apache License 2.0 4 votes vote down vote up
public PageNumberSetter(TextView textView, ViewPager viewPager) {
    this.textView = textView;
    viewPager.setOnPageChangeListener(this);
}