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

The following examples show how to use androidx.viewpager.widget.ViewPager#removeOnPageChangeListener() . 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: DeviceDetailFragment.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = super.onCreateView(inflater, container, savedInstanceState);
    viewPager = (ViewPager) (view != null ? view.findViewById(R.id.fragment_device_detail_child_view_pager) : null);
    if (viewPager != null) {
        viewPager.setOffscreenPageLimit(1);
    }
    populate();

    viewPager.removeOnPageChangeListener(onPageChangeListener);
    viewPager.addOnPageChangeListener(onPageChangeListener);
    return view;
}
 
Example 2
Source File: TabStripHelper.java    From ProjectX with Apache License 2.0 5 votes vote down vote up
private void onDetachedFromViewPager(@NonNull ViewPager pager) {
    if (mView instanceof TabStripView)
        ((TabStripView) mView).onDetachedFromViewPager(pager);
    else if (mView instanceof TabStripViewGroup)
        ((TabStripViewGroup) mView).onDetachedFromViewPager(pager);
    pager.removeOnPageChangeListener(this);
    pager.removeOnAdapterChangeListener(this);
    final PagerAdapter adapter = pager.getAdapter();
    if (adapter != null) {
        adapter.unregisterDataSetObserver(this);
    }
}
 
Example 3
Source File: ViewPagerActions.java    From android-test with Apache License 2.0 5 votes vote down vote up
@Override
public final void perform(UiController uiController, View view) {
  final ViewPager viewPager = (ViewPager) view;
  // Add a custom tracker listener
  final CustomViewPagerListener customListener = new CustomViewPagerListener();
  viewPager.addOnPageChangeListener(customListener);

  // Note that we're running the following block in a try-finally construct. This
  // is needed since some of the actions are going to throw (expected) exceptions. If that
  // happens, we still need to clean up after ourselves to leave the system (Espresso) in a good
  // state.
  try {
    // Register our listener as idling resource so that Espresso waits until the
    // wrapped action results in the view pager getting to the STATE_IDLE state
    Espresso.registerIdlingResources(customListener);

    uiController.loopMainThreadUntilIdle();

    performScroll((ViewPager) view);

    uiController.loopMainThreadUntilIdle();

    customListener.mNeedsIdle = true;
    uiController.loopMainThreadUntilIdle();
    customListener.mNeedsIdle = false;
  } finally {
    // Unregister our idling resource
    Espresso.unregisterIdlingResources(customListener);
    // And remove our tracker listener from ViewPager
    viewPager.removeOnPageChangeListener(customListener);
  }
}