Java Code Examples for android.support.v4.view.PagerAdapter#getCount()
The following examples show how to use
android.support.v4.view.PagerAdapter#getCount() .
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: TabPageIndicator.java From HomeGenie-Android with GNU General Public License v3.0 | 6 votes |
public void notifyDataSetChanged() { mTabLayout.removeAllViews(); PagerAdapter adapter = mViewPager.getAdapter(); IconPagerAdapter iconAdapter = null; if (adapter instanceof IconPagerAdapter) { iconAdapter = (IconPagerAdapter)adapter; } final int count = adapter.getCount(); for (int i = 0; i < count; i++) { CharSequence title = adapter.getPageTitle(i); if (title == null) { title = EMPTY_TITLE; } int iconResId = 0; if (iconAdapter != null) { iconResId = iconAdapter.getIconResId(i); } addTab(i, title, iconResId); } if (mSelectedTabIndex > count) { mSelectedTabIndex = count - 1; } setCurrentItem(mSelectedTabIndex); requestLayout(); }
Example 2
Source File: TabPageIndicator.java From UltimateAndroid with Apache License 2.0 | 6 votes |
public void notifyDataSetChanged() { mTabLayout.removeAllViews(); PagerAdapter adapter = mViewPager.getAdapter(); IconPagerAdapter iconAdapter = null; if (adapter instanceof IconPagerAdapter) { iconAdapter = (IconPagerAdapter)adapter; } final int count = adapter.getCount(); for (int i = 0; i < count; i++) { CharSequence title = adapter.getPageTitle(i); if (title == null) { title = EMPTY_TITLE; } int iconResId = 0; if (iconAdapter != null) { iconResId = iconAdapter.getIconResId(i); } addTab(i, title, iconResId); } if (mSelectedTabIndex > count) { mSelectedTabIndex = count - 1; } setCurrentItem(mSelectedTabIndex); requestLayout(); }
Example 3
Source File: TabPageIndicator.java From Huochexing12306 with Apache License 2.0 | 6 votes |
public void notifyDataSetChanged() { mTabLayout.removeAllViews(); PagerAdapter adapter = mViewPager.getAdapter(); IconPagerAdapter iconAdapter = null; if (adapter instanceof IconPagerAdapter) { iconAdapter = (IconPagerAdapter)adapter; } final int count = adapter.getCount(); for (int i = 0; i < count; i++) { CharSequence title = adapter.getPageTitle(i); if (title == null) { title = EMPTY_TITLE; } int iconResId = 0; if (iconAdapter != null) { iconResId = iconAdapter.getIconResId(i); } addTab(i, title, iconResId); } if (mSelectedTabIndex > count) { mSelectedTabIndex = count - 1; } setCurrentItem(mSelectedTabIndex); requestLayout(); }
Example 4
Source File: AutoScrollViewPager.java From LLApp with Apache License 2.0 | 6 votes |
/** * scroll only once */ public void scrollOnce() { PagerAdapter adapter = getAdapter(); int currentItem = getCurrentItem(); int totalCount; if (adapter == null || (totalCount = adapter.getCount()) <= 1) { return; } int nextItem = (direction == LEFT) ? --currentItem : ++currentItem; if (nextItem < 0) { if (isCycle) { setCurrentItem(totalCount - 1, isBorderAnimation); } } else if (nextItem == totalCount) { if (isCycle) { setCurrentItem(0, isBorderAnimation); } } else { setCurrentItem(nextItem, true); } }
Example 5
Source File: TabPageIndicator.java From iMoney with Apache License 2.0 | 6 votes |
public void notifyDataSetChanged() { mTabLayout.removeAllViews(); PagerAdapter adapter = mViewPager.getAdapter(); IconPagerAdapter iconAdapter = null; if (adapter instanceof IconPagerAdapter) { iconAdapter = (IconPagerAdapter)adapter; } final int count = adapter.getCount(); for (int i = 0; i < count; i++) { CharSequence title = adapter.getPageTitle(i); if (title == null) { title = EMPTY_TITLE; } int iconResId = 0; if (iconAdapter != null) { iconResId = iconAdapter.getIconResId(i); } addTab(i, title, iconResId); } if (mSelectedTabIndex > count) { mSelectedTabIndex = count - 1; } setCurrentItem(mSelectedTabIndex); requestLayout(); }
Example 6
Source File: TabPageIndicator.java From UltimateAndroid with Apache License 2.0 | 6 votes |
public void notifyDataSetChanged() { mTabLayout.removeAllViews(); PagerAdapter adapter = mViewPager.getAdapter(); IconPagerAdapter iconAdapter = null; if (adapter instanceof IconPagerAdapter) { iconAdapter = (IconPagerAdapter)adapter; } final int count = adapter.getCount(); for (int i = 0; i < count; i++) { CharSequence title = adapter.getPageTitle(i); if (title == null) { title = EMPTY_TITLE; } int iconResId = 0; if (iconAdapter != null) { iconResId = iconAdapter.getIconResId(i); } addTab(i, title, iconResId); } if (mSelectedTabIndex > count) { mSelectedTabIndex = count - 1; } setCurrentItem(mSelectedTabIndex); requestLayout(); }
Example 7
Source File: TabPageIndicator.java From zhangshangwuda with Apache License 2.0 | 6 votes |
public void notifyDataSetChanged() { mTabLayout.removeAllViews(); PagerAdapter adapter = mViewPager.getAdapter(); IconPagerAdapter iconAdapter = null; if (adapter instanceof IconPagerAdapter) { iconAdapter = (IconPagerAdapter)adapter; } final int count = adapter.getCount(); for (int i = 0; i < count; i++) { CharSequence title = adapter.getPageTitle(i); if (title == null) { title = EMPTY_TITLE; } int iconResId = 0; if (iconAdapter != null) { iconResId = iconAdapter.getIconResId(i); } addTab(i, title, iconResId); } if (mSelectedTabIndex > count) { mSelectedTabIndex = count - 1; } setCurrentItem(mSelectedTabIndex); requestLayout(); }
Example 8
Source File: TabPageIndicator.java From barterli_android with Apache License 2.0 | 6 votes |
public void notifyDataSetChanged() { mTabLayout.removeAllViews(); PagerAdapter adapter = mViewPager.getAdapter(); IconPagerAdapter iconAdapter = null; if (adapter instanceof IconPagerAdapter) { iconAdapter = (IconPagerAdapter)adapter; } final int count = adapter.getCount(); for (int i = 0; i < count; i++) { CharSequence title = adapter.getPageTitle(i); if (title == null) { title = EMPTY_TITLE; } int iconResId = 0; if (iconAdapter != null) { iconResId = iconAdapter.getIconResId(i); } addTab(i, title, iconResId); } if (mSelectedTabIndex > count) { mSelectedTabIndex = count - 1; } setCurrentItem(mSelectedTabIndex); requestLayout(); }
Example 9
Source File: TabPageIndicator.java From Atomic with GNU General Public License v3.0 | 6 votes |
public void notifyDataSetChanged() { mTabLayout.removeAllViews(); PagerAdapter adapter = mViewPager.getAdapter(); final int count = adapter.getCount(); for (int i = 0; i < count; i++) { CharSequence title = adapter.getPageTitle(i); if (title == null) { title = EMPTY_TITLE; } addTab(title, i); } if (mSelectedTabIndex > count) { mSelectedTabIndex = count - 1; } setCurrentItem(mSelectedTabIndex); requestLayout(); }
Example 10
Source File: RtlViewPager.java From IslamicLibraryAndroid with GNU General Public License v3.0 | 5 votes |
@Override public void setCurrentItem(int position, boolean smoothScroll) { PagerAdapter adapter = super.getAdapter(); if (adapter != null && isRtl()) { position = adapter.getCount() - position - 1; } super.setCurrentItem(position, smoothScroll); }
Example 11
Source File: SlidePager.java From SlidePager with MIT License | 5 votes |
@Override public void setAdapter(PagerAdapter adapter) { if (!(adapter instanceof AbstractSlidePagerAdapter)) { throw new IllegalArgumentException("PagerAdapter should be a subclass of AbstractSlidePagerAdapter"); } super.setAdapter(adapter); if (mStartAtEnd) { int position = adapter.getCount() - 1; setCurrentItem(position >= 0 ? position : 0); } }
Example 12
Source File: SmartTabLayout.java From RecyclerPager with Apache License 2.0 | 5 votes |
@Override protected void populateTabStrip() { final PagerAdapter adapter = viewPager.getAdapter(); if (adapter == null) { return; } for (int i = 0; i < adapter.getCount(); i++) { CharSequence title = adapter.getPageTitle(i); final View tabView = (tabProvider == null) ? createDefaultTabView(title) : tabProvider.createTabView(tabStrip, i, title); if (tabView == null) { throw new IllegalStateException("tabView is null."); } if (distributeEvenly) { LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams(); lp.width = 0; lp.weight = 1; } if (internalTabClickListener != null) { tabView.setOnClickListener(internalTabClickListener); } tabStrip.addView(tabView); if (i == getCurrentItem()) { tabView.setSelected(true); } } }
Example 13
Source File: PullToRefreshViewPager.java From ONE-Unofficial with Apache License 2.0 | 5 votes |
@Override protected boolean isReadyForPullEnd() { ViewPager refreshableView = getRefreshableView(); PagerAdapter adapter = refreshableView.getAdapter(); if (null != adapter) { return refreshableView.getCurrentItem() == adapter.getCount() - 1; } return false; }
Example 14
Source File: SmartTabLayout.java From SmartTablayout with Apache License 2.0 | 5 votes |
private void populateTabStrip() { final PagerAdapter adapter = viewPager.getAdapter(); final OnClickListener tabClickListener = new TabClickListener(); for (int i = 0; i < adapter.getCount(); i++) { final View tabView = (tabProvider == null) ? createDefaultTabView(adapter.getPageTitle(i)) : tabProvider.createTabView(tabStrip, i, adapter); if (tabView == null) { throw new IllegalStateException("tabView is null."); } if (distributeEvenly) { LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams(); lp.width = 0; lp.weight = 1; } tabView.setOnClickListener(tabClickListener); tabStrip.addView(tabView); if (i == viewPager.getCurrentItem()) { tabView.setSelected(true); } } }
Example 15
Source File: LVCustomViewPagerIndicator.java From VideoOS-Android-SDK with GNU General Public License v3.0 | 5 votes |
@Override public void notifyDataSetChanged() { mLayout.removeAllViews(); PagerAdapter adapter = mViewPager.getAdapter(); int count = adapter.getCount(); for (int i = 0; i < count; i++) { View view = createAndRenderView(i); mLayout.addView(view); } if (mSelectedIndex > count) { mSelectedIndex = count - 1; } setCurrentItem(mSelectedIndex); requestLayout(); }
Example 16
Source File: NumContainer.java From LoyalNativeSlider with MIT License | 5 votes |
@Override public void onChanged() { PagerAdapter adapter = mPager.getAdapter(); if (adapter instanceof InfinitePagerAdapter) { mTotalSlides = ((InfinitePagerAdapter) adapter).getRealCount(); } else { mTotalSlides = adapter.getCount(); } }
Example 17
Source File: RtlViewPager.java From IslamicLibraryAndroid with GNU General Public License v3.0 | 5 votes |
@Override public void onPageSelected(int position) { PagerAdapter adapter = RtlViewPager.super.getAdapter(); if (isRtl() && adapter != null) { position = adapter.getCount() - position - 1; } mListener.onPageSelected(position); }
Example 18
Source File: InfiniteViewPager.java From InfiniteViewPager with MIT License | 5 votes |
public static int getAdapterSize(ViewPager viewPager) { if (viewPager instanceof InfiniteViewPager) { InfiniteViewPager infiniteViewPager = (InfiniteViewPager) viewPager; return getRealAdapterSize(infiniteViewPager); } PagerAdapter adapter = viewPager.getAdapter(); if (adapter instanceof InfinitePagerAdapter) { InfinitePagerAdapter infinitePagerAdapter = (InfinitePagerAdapter) viewPager.getAdapter(); return infinitePagerAdapter.getItemCount(); } return adapter == null ? 0 : adapter.getCount(); }
Example 19
Source File: CircularTabLayout.java From CircularViewPager with MIT License | 4 votes |
public void setTabsFromPagerAdapter(@NonNull PagerAdapter adapter) { List<Tab> list = new ArrayList<>(); if (adapter instanceof ITabSetting) { for (int i = 0, count = adapter.getCount(); i < count; ++i) { list.add(((ITabSetting) adapter).getTabItem(i)); } } else { for (int i = 0, count = adapter.getCount(); i < count; ++i) { list.add(new Tab(getContext()).setText(adapter.getPageTitle(i))); } } mCircularTabLayoutAdapter = new CircularTabLayoutAdapter(getContext(), new ITabSelectedListener() { @Override public void onTabItemClicked(int position) { smoothScrollToPositionFromTabSelect(position); } }); mCircularTabLayoutAdapter.setTabData(list); setTabViewStyle(); getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @SuppressWarnings("deprecation") @SuppressLint("NewApi") @Override public void onGlobalLayout() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { getViewTreeObserver().removeGlobalOnLayoutListener(this); } else { getViewTreeObserver().removeOnGlobalLayoutListener(this); } LinearLayoutManager linearLayoutManager = (LinearLayoutManager) getLayoutManager(); View targetView = linearLayoutManager.findViewByPosition(0); if (targetView != null) { RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) targetView.getLayoutParams(); int start = linearLayoutManager.getPaddingLeft(); int end = linearLayoutManager.getWidth() - linearLayoutManager.getPaddingRight(); int left = linearLayoutManager.getDecoratedLeft(targetView) - params.leftMargin; int right = linearLayoutManager.getDecoratedRight(targetView) + params.rightMargin; int offset = (start + ((end - start) / 2 - (right - left) / 2)) - left; linearLayoutManager.scrollToPositionWithOffset( mCircularTabLayoutAdapter.getCurrentPosition(), offset); } } }); }
Example 20
Source File: TabLayout.java From attendee-checkin with Apache License 2.0 | 2 votes |
/** * Add new {@link Tab}s populated from a {@link PagerAdapter}. Each tab will have it's text set * to the value returned from {@link PagerAdapter#getPageTitle(int)}. * * @param adapter the adapter to populate from */ public void addTabsFromPagerAdapter(PagerAdapter adapter) { for (int i = 0, count = adapter.getCount(); i < count; i++) { addTab(newTab().setText(adapter.getPageTitle(i))); } }