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