本文整理汇总了Java中android.support.v4.view.ViewPager.setCurrentItem方法的典型用法代码示例。如果您正苦于以下问题:Java ViewPager.setCurrentItem方法的具体用法?Java ViewPager.setCurrentItem怎么用?Java ViewPager.setCurrentItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.view.ViewPager
的用法示例。
在下文中一共展示了ViewPager.setCurrentItem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupViewPager
import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
private void setupViewPager(ViewPager viewPager) {
String[] titles = {getString(R.string.crashes), getString(R.string.exceptions)};
mainPagerAdapter = new MainPagerAdapter(getSupportFragmentManager(), titles);
viewPager.setAdapter(mainPagerAdapter);
viewPager.addOnPageChangeListener(new SimplePageChangeListener() {
@Override
public void onPageSelected(int position) {
selectedTabPosition = position;
}
});
Intent intent = getIntent();
if (intent != null && !intent.getBooleanExtra(Constants.LANDING, false)) {
selectedTabPosition = 1;
}
viewPager.setCurrentItem(selectedTabPosition);
}
示例2: onCreate
import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_preview);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setTitle("");
Bundle bundle = getIntent().getExtras();
position = bundle.getInt("position", 0);
// Create the adapter that will return a fragment for each of the three
// primary sections of the activity.
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);
mViewPager.setCurrentItem(position);
mViewPager.setPageMargin(UiUtil.convertDpToPx(this, 16));
}
示例3: onCreate
import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
viewPager = (ViewPager) findViewById(R.id.viewpager);
setupViewPager(viewPager);
tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewPager);
setTabLayoutListener();
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
initTabIcons();
//default position
viewPager.setCurrentItem(1);
}
示例4: onCreate
import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
tabLayout = (MainTabLayout) findViewById(R.id.main_activity_tab_layout);
viewPager = (ViewPager) findViewById(R.id.main_activity_view_pager);
pagerAdapter = createAdapter();
viewPager.setOffscreenPageLimit(5);
viewPager.setAdapter(pagerAdapter);
tabLayout.setupWithViewPager(viewPager);
viewPager.setCurrentItem(2);
Intent intent = new Intent(this, LocationService.class);
startService(intent);
}
示例5: onViewCreatedOk
import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
@Override
public void onViewCreatedOk(View view, @Nullable Bundle savedInstanceState) {
mCbCheck = (AppCompatCheckBox) view.findViewById(R.id.cb_page_check);
mViewPager = (ViewPager) view.findViewById(R.id.view_pager_page);
mRlRootView = (RelativeLayout) view.findViewById(R.id.rl_page_root_view);
mScreenSize = DeviceUtils.getScreenSize(getContext());
mMediaBeanList = new ArrayList<>();
if (savedInstanceState != null) {
List<MediaBean> mediaList = savedInstanceState.getParcelableArrayList(EXTRA_MEDIA_LIST);
mItemClickPosition = savedInstanceState.getInt(EXTRA_ITEM_CLICK_POSITION);
if (mediaList != null) {
mMediaBeanList.addAll(mediaList);
}
}
mMediaPreviewAdapter = new MediaPreviewAdapter(mMediaBeanList,
mScreenSize.widthPixels, mScreenSize.heightPixels, mConfiguration
, ThemeUtils.resolveColor(getActivity(), R.attr.gallery_page_bg, R.color.gallery_default_page_bg),
ContextCompat.getDrawable(getActivity(), ThemeUtils.resolveDrawableRes(getActivity(), R.attr.gallery_default_image, R.drawable.gallery_default_image)));
mViewPager.setAdapter(mMediaPreviewAdapter);
mCbCheck.setOnClickListener(this);
mViewPager.setCurrentItem(mItemClickPosition);
mViewPager.addOnPageChangeListener(this);
}
示例6: onCreate
import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
overridePendingTransition(R.anim.fade_in,R.anim.fade_out);
// Set title for the ViewPager
setTitle("ViewPager");
// Get the view from view_pager.xml
setContentView(R.layout.view_pager);
// Retrieve data from MainActivity on item click event
Intent p = getIntent();
position = p.getExtras().getInt("id");
ImageAdapter imageAdapter = new ImageAdapter(this);
List<ImageView> images = new ArrayList<ImageView>();
// Retrieve all the images
for (int i = 0; i < imageAdapter.getCount(); i++) {
ImageView imageView = new ImageView(this);
//imageView.setImageResource(imageAdapter.mThumbIds[i]);
Picasso.with(this)
.load(GalleryFragment.mThumbIds[i])
.placeholder(R.drawable.loading)
.error(R.drawable.error)
.into(imageView);
imageView.setScaleType(ImageView.ScaleType.CENTER);
//imageView.setScaleType(ImageView.ScaleType.CENTER);
images.add(imageView);
}
// Set the images into ViewPager
ImagePagerAdapter pageradapter = new ImagePagerAdapter(images);
ViewPager viewpager = (ViewPager) findViewById(R.id.pager);
viewpager.setAdapter(pageradapter);
viewpager.setPageTransformer(true, new ZoomOutPageTransformer());
// Show images following the position
viewpager.setCurrentItem(position);
}
示例7: onCreate
import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_activity_layout);
mViewPager = (ViewPager)findViewById(R.id.fragment_pager);
imageFragment = Fragment.instantiate(this, ImageFragment.class.getName());
textFragment = Fragment.instantiate(this, TextFragment.class.getName());
image2Fragment = Fragment.instantiate(this, ImageFragment.class.getName());
text2Fragment = Fragment.instantiate(this, TextFragment.class.getName());
mViewPager.setOffscreenPageLimit(4);
mViewPager.setCurrentItem(0);
mViewPager.setAdapter(new FPagerAdapter(getSupportFragmentManager()));
}
示例8: onOptionsItemSelected
import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
viewPager.setCurrentItem(3);
return true;
}else if (id == android.R.id.home) {
drawerLayout.openDrawer(GravityCompat.START);
}
return super.onOptionsItemSelected(item);
}
示例9: onCreate
import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_crime_pager);
UUID crimeId = (UUID) getIntent()
.getSerializableExtra(EXTRA_CRIME_ID);
mViewPager = (ViewPager) findViewById(R.id.crime_view_pager);
mCrimes = CrimeLab.get(this).getCrimes();
FragmentManager fragmentManager = getSupportFragmentManager();
mViewPager.setAdapter(new FragmentStatePagerAdapter(fragmentManager) {
@Override
public Fragment getItem(int position) {
Crime crime = mCrimes.get(position);
return CrimeFragment.newInstance(crime.getId());
}
@Override
public int getCount() {
return mCrimes.size();
}
});
for (int i = 0; i < mCrimes.size(); i++) {
if (mCrimes.get(i).getId().equals(crimeId)) {
mViewPager.setCurrentItem(i);
break;
}
}
}
示例10: onCreate
import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_crime_pager);
mViewPager = (ViewPager)findViewById(R.id.activity_crime_pager_view_pager);
mCrimes = CrimeLab.get(this).getCrimes();
FragmentManager fm = getSupportFragmentManager();
mViewPager.setAdapter(new FragmentStatePagerAdapter(fm) {
@Override
public Fragment getItem(int position) {
Crime crime = mCrimes.get(position);
return CrimeFragment.newInstance(crime.getId());
}
@Override
public int getCount() {
return mCrimes.size();
}
});
UUID crimeId = (UUID)getIntent().getSerializableExtra(EXTRA_CRIME_ID);
for (int i = 0; i < mCrimes.size(); i++) {
if (mCrimes.get(i).getId().equals(crimeId)) {
mViewPager.setCurrentItem(i);
break;
}
}
}
示例11: addWeekView
import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
private void addWeekView() {
View calendar = LayoutInflater.from(getContext()).inflate(R.layout.layout_calendar_content, this, false);
calendar.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, calendarHeight));
viewPagerContent = (ViewPager) calendar.findViewById(R.id.viewpager_calendar);
addView(calendar);
DateTime startDay = new DateTime(DateTimeZone.UTC);
startDay = startDay.minusDays(startDay.getDayOfWeek() % DAYS_OF_WEEK);
calendarPagerAdapter = new CalendarPagerAdapter(getContext(), maxCount, startDay, getViewHelper);
viewPagerContent.setAdapter(calendarPagerAdapter);
viewPagerContent.setCurrentItem(centerPosition);
}
示例12: onCreate
import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_crime_pager);
UUID crimeId = (UUID) getIntent()
.getSerializableExtra(EXTRA_CRIME_ID);
mViewPager = (ViewPager) findViewById(R.id.view_pager);
mCrimes = CrimeLab.get(this).getCrimes();
FragmentManager fragmentManager = getSupportFragmentManager();
mViewPager.setAdapter(new FragmentStatePagerAdapter(fragmentManager) {
@Override
public Fragment getItem(int position) {
Crime crime = mCrimes.get(position);
return CrimeFragment.newInstance(crime.getId());
}
@Override
public int getCount() {
return mCrimes.size();
}
});
for (int i = 0; i < mCrimes.size(); i++) {
if (mCrimes.get(i).getId().equals(crimeId)) {
mViewPager.setCurrentItem(i);
break;
}
}
}
示例13: onCreate
import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mViewpager = (ViewPager) findViewById(R.id.viewpager);
mTabLayout = (TabLayout) findViewById(R.id.tab_layout);
mAdBannerFragment = new AdBannerFragment();
mAdLargeFragment = new AdLargeFragment();
mAdRectangleFragment = new AdRectangleFragment();
mAdInfoFlowFragment = new AdInfoFlowFragment();
ArrayList<BasePagerAdapter.FragmentModel> mLists = new ArrayList<>();
mLists.add(new BasePagerAdapter.FragmentModel("信息流", mAdInfoFlowFragment));
mLists.add(new BasePagerAdapter.FragmentModel("大图", mAdLargeFragment));
mLists.add(new BasePagerAdapter.FragmentModel("方图", mAdRectangleFragment));
mLists.add(new BasePagerAdapter.FragmentModel("横幅", mAdBannerFragment));
mViewPagerAdapter = new BasePagerAdapter(getSupportFragmentManager(), mLists);
mViewpager.setAdapter(mViewPagerAdapter);
mViewpager.setCurrentItem(0);
mTabLayout.setupWithViewPager(mViewpager);
// 添加一个广告下载监听器
mMyOnYoumiNativeAdDownloadListener = new MyOnYoumiNativeAdDownloadListener(this);
YoumiNativeAdHelper.addOnYoumiNativeAdDownloadListener(mMyOnYoumiNativeAdDownloadListener);
}
示例14: onCreate
import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_barcode);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
setTitle(R.string.barcode);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
String text = getIntent().getStringExtra("data");
if (text == null) text = "";
toolbar.setSubtitle(text);
ViewPager viewPager = findViewById(R.id.view_pager);
viewPager.setAdapter(new BarcodeEncodedPagerAdapter(getSupportFragmentManager(), text));
viewPager.setOffscreenPageLimit(3);
viewPager.setCurrentItem(8); //barcode
((TabLayout) findViewById(R.id.tab_layout)).setupWithViewPager(viewPager);
if (Premium.isPremium(this)){
View containerAd = findViewById(R.id.ads_wrapper);
if (containerAd != null) containerAd.setVisibility(View.GONE);
}else {
AdsManager.loadAds(this, findViewById(R.id.ads_wrapper), findViewById(R.id.ad_view));
}
}
示例15: setupViewPager
import android.support.v4.view.ViewPager; //导入方法依赖的package包/类
private void setupViewPager(ViewPager viewPager) {
Adapter adapter = new Adapter(getSupportFragmentManager());
adapter.addFragment(new ListContentFragment(), "Postulaciones aceptadas");
adapter.addFragment(new CardContentFragment(), "En este momento");
adapter.addFragment(new TileContentFragment(), "Categorias");
viewPager.setAdapter(adapter);
viewPager.setCurrentItem(1);
}