本文整理汇总了Java中android.support.v4.view.PagerAdapter类的典型用法代码示例。如果您正苦于以下问题:Java PagerAdapter类的具体用法?Java PagerAdapter怎么用?Java PagerAdapter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PagerAdapter类属于android.support.v4.view包,在下文中一共展示了PagerAdapter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: defaultUltraViewPager
import android.support.v4.view.PagerAdapter; //导入依赖的package包/类
/**
*
*/
private void defaultUltraViewPager(){
UltraViewPager ultraViewPager = (UltraViewPager)findViewById(R.id.ultra_viewpager);
ultraViewPager.setScrollMode(UltraViewPager.ScrollMode.HORIZONTAL);
//initialize UltraPagerAdapter,and add child view to UltraViewPager
PagerAdapter adapter = new UltraPagerAdapter(false);
ultraViewPager.setAdapter(adapter);
//initialize built-in indicator
ultraViewPager.initIndicator();
//set style of indicators
ultraViewPager.getIndicator()
.setOrientation(UltraViewPager.Orientation.HORIZONTAL)
.setFocusColor(Color.GREEN)
.setNormalColor(Color.WHITE)
.setRadius((int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, getResources().getDisplayMetrics()));
//set the alignment
ultraViewPager.getIndicator().setGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
//construct built-in indicator, and add it to UltraViewPager
ultraViewPager.getIndicator().build();
//set an infinite loop
ultraViewPager.setInfiniteLoop(true);
//enable auto-scroll mode
ultraViewPager.setAutoScroll(2000);
}
示例2: initView
import android.support.v4.view.PagerAdapter; //导入依赖的package包/类
private void initView() {
PagerAdapter adapter = mViewPager.getAdapter();
if (autoHide) {
if (adapter == null) {
setVisibility(INVISIBLE);
} else {
setVisibility(VISIBLE);
setText((mViewPager.getCurrentItem() + 1) + "/" + adapter.getCount());
}
} else {
if (adapter == null) {
} else {
setText((mViewPager.getCurrentItem() + 1) + "/" + adapter.getCount());
}
}
}
示例3: setAdapter
import android.support.v4.view.PagerAdapter; //导入依赖的package包/类
@Override
public void setAdapter(PagerAdapter adapter) {
wrappedPagerAdapter = adapter;
//若设置的 adapter 不为空则对其进行包装
wrapperPagerAdapter = (wrappedPagerAdapter == null) ? null : new AutoScrollPagerAdapter(adapter);
super.setAdapter(wrapperPagerAdapter); //为viewPager设置的是包装的adapter
if (adapter != null && adapter.getCount() != 0) {
post(new Runnable() {
@Override
public void run() {
setCurrentItem(0, false);
}
});
}
startAutoScroll();
}
示例4: setViewPager
import android.support.v4.view.PagerAdapter; //导入依赖的package包/类
@Override
public void setViewPager(ViewPager view) {
if (mViewPager == view) {
return;
}
if (mViewPager != null) {
mViewPager.setOnPageChangeListener(null);
}
final PagerAdapter adapter = view.getAdapter();
if (adapter == null) {
throw new IllegalStateException("ViewPager does not have adapter instance.");
}
mViewPager = view;
view.setOnPageChangeListener(this);
notifyDataSetChanged();
}
示例5: notifyDataSetChanged
import android.support.v4.view.PagerAdapter; //导入依赖的package包/类
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();
}
示例6: setAdapter
import android.support.v4.view.PagerAdapter; //导入依赖的package包/类
@Override
public void setAdapter(PagerAdapter adapter) {
if (adapter != null) {
if (pagerAdapter == null || pagerAdapter.getAdapter() != adapter) {
pagerAdapter = new UltraViewPagerAdapter(adapter);
pagerAdapter.setCenterListener(this);
pagerAdapter.setEnableLoop(enableLoop);
pagerAdapter.setMultiScrRatio(multiScrRatio);
needsMeasurePage = true;
constrainLength = 0;
super.setAdapter(pagerAdapter);
}
} else {
super.setAdapter(adapter);
}
}
示例7: setViewPager
import android.support.v4.view.PagerAdapter; //导入依赖的package包/类
@Override
public void setViewPager(ViewPager view) {
Logger.d("set ViewPager");
if (mViewPager == view) {
return;
}
if (mViewPager != null) {
mViewPager.setOnPageChangeListener(null);
}
final PagerAdapter adapter = view.getAdapter();
if (adapter == null) {
throw new IllegalStateException("ViewPager does not have adapter instance.");
}
mViewPager = view;
view.setOnPageChangeListener(this);
notifyDataSetChanged();
}
示例8: setViewPager
import android.support.v4.view.PagerAdapter; //导入依赖的package包/类
@Override
public void setViewPager(ViewPager view) {
if (mViewPager == view) {
return;
}
if (mViewPager != null) {
mViewPager.setOnPageChangeListener(null);
}
PagerAdapter adapter = view.getAdapter();
if (adapter == null) {
throw new IllegalStateException("ViewPager does not have adapter instance.");
}
mViewPager = view;
view.setOnPageChangeListener(this);
notifyDataSetChanged();
}
示例9: bind
import android.support.v4.view.PagerAdapter; //导入依赖的package包/类
private static void bind(ViewPager container, final ItemView itemView, final List<?> datas, final OnItemClickListener<?> onItemClickListener) {
PagerAdapter adapter;
if (datas != null && !datas.isEmpty()) {
adapter = container.getAdapter();
if(adapter == null) {
// initialize, adapter is only set once !!!
container.setAdapter(adapter = new CommonPagerAdapter<Object>(container.getContext(), itemView.layoutRes(), (List<Object>)datas) {
@Override
protected void convert(ViewHolder holder, Object data, int position) {
DataBindingUtil.bind(holder.itemView).setVariable(itemView.bindingVariable(), data);
}
});
((CommonPagerAdapter<Object>)adapter).setOnItemClickListener((OnItemClickListener<Object>)onItemClickListener);
}
adapter.notifyDataSetChanged();
}
}
示例10: populateTabStrip
import android.support.v4.view.PagerAdapter; //导入依赖的package包/类
private void populateTabStrip() {
final PagerAdapter adapter = viewPager.getAdapter();
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;
}
if (internalTabClickListener != null) {
tabView.setOnClickListener(internalTabClickListener);
}
tabStrip.addView(tabView);
if (i == viewPager.getCurrentItem()) {
tabView.setSelected(true);
}
}
}
示例11: notifyDataSetChanged
import android.support.v4.view.PagerAdapter; //导入依赖的package包/类
public void notifyDataSetChanged() {
this.mTabLayout.removeAllViews();
PagerAdapter adapter = this.mViewPager.getAdapter();
IconPagerAdapter iconAdapter = null;
if (adapter instanceof IconPagerAdapter) {
iconAdapter = (IconPagerAdapter) adapter;
}
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 (this.mSelectedTabIndex > count) {
this.mSelectedTabIndex = count - 1;
}
setCurrentItem(this.mSelectedTabIndex);
requestLayout();
}
示例12: scrollOnce
import android.support.v4.view.PagerAdapter; //导入依赖的package包/类
/**
* 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);
}
}
示例13: setupWithViewPager
import android.support.v4.view.PagerAdapter; //导入依赖的package包/类
private void setupWithViewPager(@NonNull ViewPager viewPager) {
mViewPager = viewPager;
PagerAdapter adapter = viewPager.getAdapter();
if (adapter == null) {
throw new IllegalArgumentException("ViewPager does not have a PagerAdapter set");
}
setTabsFromPagerAdapter(adapter);
viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
public void onPageSelected(int position) {
if (!mScrollingByManual) {
smoothScrollToPosition(mCircularTabLayoutAdapter.moveToPosition(position));
}
mScrollingByManual = false;
}
});
}
示例14: setAdapter
import android.support.v4.view.PagerAdapter; //导入依赖的package包/类
@Override
public void setAdapter(PagerAdapter adapter) {
if (adapter instanceof QMUIPagerAdapter) {
super.setAdapter(new WrapperPagerAdapter((QMUIPagerAdapter) adapter));
} else {
super.setAdapter(adapter);
}
}
示例15: listenToAdapterChanges
import android.support.v4.view.PagerAdapter; //导入依赖的package包/类
private void listenToAdapterChanges(PagerAdapter pagerAdapter) {
if (adapter != null) {
adapter.unregisterDataSetObserver(adapterObserver);
}
if (pagerAdapter == null) {
Log.e(TAG, "listenToAdapterChanges - pager adapter is null. can't register");
return;
}
this.adapter = pagerAdapter;
this.adapter.registerDataSetObserver(adapterObserver);
notifyDatasetChanged();
}