當前位置: 首頁>>代碼示例>>Java>>正文


Java ViewPager.getCurrentItem方法代碼示例

本文整理匯總了Java中android.support.v4.view.ViewPager.getCurrentItem方法的典型用法代碼示例。如果您正苦於以下問題:Java ViewPager.getCurrentItem方法的具體用法?Java ViewPager.getCurrentItem怎麽用?Java ViewPager.getCurrentItem使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.support.v4.view.ViewPager的用法示例。


在下文中一共展示了ViewPager.getCurrentItem方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: handleBackPress

import android.support.v4.view.ViewPager; //導入方法依賴的package包/類
/**
 * 將back事件分發給ViewPager中的Fragment,{@link #handleBackPress(FragmentManager)} 已經實現了對ViewPager的支持,所以自行決定是否使用該方法
 *
 * @return 如果處理了back鍵則返回 <b>true</b>
 * @see #handleBackPress(FragmentManager)
 * @see #handleBackPress(Fragment)
 * @see #handleBackPress(FragmentActivity)
 */
public static boolean handleBackPress(ViewPager viewPager) {
    if (viewPager == null) return false;
    PagerAdapter adapter = viewPager.getAdapter();
    if (adapter == null) return false;
    int currentItem = viewPager.getCurrentItem();
    Fragment fragment;
    if (adapter instanceof FragmentPagerAdapter) {
        fragment = ((FragmentPagerAdapter) adapter).getItem(currentItem);
    } else if (adapter instanceof FragmentStatePagerAdapter) {
        fragment = ((FragmentStatePagerAdapter) adapter).getItem(currentItem);
    } else {
        fragment = null;
    }
    return isFragmentBackHandled(fragment);
}
 
開發者ID:yangchong211,項目名稱:YCUtils,代碼行數:24,代碼來源:BackHandlerHelper.java

示例2: setViewPagerCircle

import android.support.v4.view.ViewPager; //導入方法依賴的package包/類
/**
 * For circular adapter, where 2 fake page (first and last)
 */
public void setViewPagerCircle(ViewPager viewPager) {
  k = 1;
  viewPager.addOnPageChangeListener(this);
  max = viewPager.getAdapter().getCount();
  current = viewPager.getCurrentItem();
  if (current == 0) {
    current++;
    viewPager.setCurrentItem(current);
  }
  if (current == max) {
    current--;
    viewPager.setCurrentItem(current);
  }
  update();
}
 
開發者ID:AtlantPlatform,項目名稱:atlant-android,代碼行數:19,代碼來源:IndicatorCircleView.java

示例3: setupWithViewPager

import android.support.v4.view.ViewPager; //導入方法依賴的package包/類
public void setupWithViewPager(ViewPager viewPager) {
PagerAdapter adapter = viewPager.getAdapter();
if (adapter == null) {
  throw new IllegalArgumentException("ViewPager does not have a PagerAdapter set");
} else {
  this.addTabsFromPagerAdapter(adapter);
  viewPager.setOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(this));
  this.setOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(viewPager));
  if (this.mSelectedTab == null || this.mSelectedTab.getPosition() != viewPager.getCurrentItem()) {
	this.getTabAt(viewPager.getCurrentItem()).select();
  }

}
 }
 
開發者ID:TIIEHenry,項目名稱:TIIEHenry-Android-SDK,代碼行數:15,代碼來源:TabLayout.java

示例4: isReadyForPullStart

import android.support.v4.view.ViewPager; //導入方法依賴的package包/類
@Override
protected boolean isReadyForPullStart() {
	ViewPager refreshableView = getRefreshableView();

	PagerAdapter adapter = refreshableView.getAdapter();
	if (null != adapter) {
		return refreshableView.getCurrentItem() == 0;
	}

	return false;
}
 
開發者ID:SavorGit,項目名稱:Hotspot-master-devp,代碼行數:12,代碼來源:PullToRefreshViewPager.java

示例5: isReadyForPullEnd

import android.support.v4.view.ViewPager; //導入方法依賴的package包/類
@Override
protected boolean isReadyForPullEnd() {
	ViewPager refreshableView = getRefreshableView();

	PagerAdapter adapter = refreshableView.getAdapter();
	if (null != adapter) {
		return refreshableView.getCurrentItem() == adapter.getCount() - 1;
	}

	return false;
}
 
開發者ID:SavorGit,項目名稱:Hotspot-master-devp,代碼行數:12,代碼來源:PullToRefreshViewPager.java

示例6: getCurrentView

import android.support.v4.view.ViewPager; //導入方法依賴的package包/類
public View getCurrentView(ViewPager pager) {
    for (int i = 0; i < pager.getChildCount(); i++) {
        if ((int) pager.getChildAt(i).getTag(R.id.index) == pager.getCurrentItem()) {
            return pager.getChildAt(i);
        }
    }

    return null;
}
 
開發者ID:adithya321,項目名稱:Instincts-2k17,代碼行數:10,代碼來源:GalleryViewPagerAdapter.java

示例7: onInterceptTouchEvent

import android.support.v4.view.ViewPager; //導入方法依賴的package包/類
/**
 * 事件攔截操作
 */
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    //處理ViewPager衝突問題
    ViewPager mViewPager = getTouchViewPager(mViewPagers, ev);
    if (mViewPager != null && mViewPager.getCurrentItem() != 0) {
        return super.onInterceptTouchEvent(ev);
    }
    switch (ev.getAction()) {
        case MotionEvent.ACTION_DOWN:
            downX = tempX = (int) ev.getRawX();
            downY = (int) ev.getRawY();
            canSwipe = downX <= viewWidth / 2;
            if (!canSwipe) {
                return super.onInterceptTouchEvent(ev);
            }
            break;
        case MotionEvent.ACTION_MOVE:
            if (!canSwipe) {
                return super.onInterceptTouchEvent(ev);
            }
            int moveX = (int) ev.getRawX();
            // 滿足此條件屏蔽SildingFinishLayout裏麵子類的touch事件
            if (moveX - downX > mTouchStop && Math.abs((int) ev.getRawY() - downY) < mTouchStop) {
                return true;
            }
            break;
    }

    return super.onInterceptTouchEvent(ev);
}
 
開發者ID:haihaio,項目名稱:AmenEye,代碼行數:34,代碼來源:SwipeBackLayout.java

示例8: displayNextFragment

import android.support.v4.view.ViewPager; //導入方法依賴的package包/類
private void displayNextFragment() {
  ViewPager vp = (ViewPager) getActivity().findViewById(R.id.container);
  int currentItem = vp.getCurrentItem();
  if (currentItem < vp.getAdapter().getCount()) {
    vp.setCurrentItem(currentItem + 1);
  }
}
 
開發者ID:Komdosh,項目名稱:SocEltech,代碼行數:8,代碼來源:TestViewFragment.java

示例9: setViewPager

import android.support.v4.view.ViewPager; //導入方法依賴的package包/類
public void setViewPager(ViewPager viewPager) {
  k = 0;
  viewPager.addOnPageChangeListener(this);
  max = viewPager.getAdapter().getCount();
  current = viewPager.getCurrentItem();
  update();
}
 
開發者ID:AtlantPlatform,項目名稱:atlant-android,代碼行數:8,代碼來源:IndicatorCircleView.java

示例10: canViewPagerScrollHorizontally

import android.support.v4.view.ViewPager; //導入方法依賴的package包/類
boolean canViewPagerScrollHorizontally(ViewPager p, int dx) {
    return !(dx < 0 && p.getCurrentItem() <= 0 ||
            0 < dx && p.getAdapter().getCount() - 1 <= p.getCurrentItem());
}
 
開發者ID:chemickypes,項目名稱:Glitchy,代碼行數:5,代碼來源:SideMenu.java


注:本文中的android.support.v4.view.ViewPager.getCurrentItem方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。