public void setViewPager(ExtendedViewPager pager) { final PagerAdapter adapter = pager.getAdapter(); if (adapter == null) return; // throw new IllegalStateException("ViewPager has not been bound."); if (!(adapter instanceof TitleProvider)) throw new IllegalStateException( "ViewPager adapter must implement TitleProvider to be used with TitlePageIndicator."); mViewPager = pager; pager.setOnPageChangeListener(this); notifyDataSetChanged(); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ImageUtil.initImageLoader(this); int pos = getIntent().getIntExtra("pos", 0); imgs = getIntent().getStringArrayListExtra("Images"); setContentView(R.layout.activity_viewpager_example); ExtendedViewPager mViewPager = (ExtendedViewPager) findViewById(R.id.view_pager); mViewPager.setAdapter(new TouchImageAdapter()); mViewPager.setCurrentItem(pos); }
public void setCurrentItem(int item) { if (mViewPager == null) return; // throw new IllegalStateException("ViewPager has not been bound."); mCurrentItem = item; mViewPager.setCurrentItem(item); mSelectedTabIndex = item; final int tabCount = mTabLayout.getChildCount(); for (int i = 0; i < tabCount; i++) { final View child = mTabLayout.getChildAt(i); final boolean isSelected = i == item; child.setSelected(isSelected); if (isSelected) { animateToTab(item); } } }
public void notifyDataSetChanged() { if (mTabLayout == null || mViewPager == null) return; mTabLayout.removeAllViews(); mAdapter = (TitleProvider) mViewPager.getAdapter(); if (mAdapter == null) return; final int count = ((PagerAdapter) mAdapter).getCount(); for (int i = 0; i < count; i++) { final String title = mAdapter.getTitle(i); final Drawable icon = mAdapter.getIcon(i); if (title != null && icon != null) { addTab(title, icon, i); } else if (title == null && icon != null) { addTab(icon, i); } else if (title != null && icon == null) { addTab(title, i); } } if (mSelectedTabIndex > count) { mSelectedTabIndex = count - 1; } setCurrentItem(mSelectedTabIndex); requestLayout(); }
public void setPagingEnabled(boolean enabled) { mViewPager.setPagingEnabled(enabled); mPagingEnabled = enabled; }