本文整理汇总了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());
}