当前位置: 首页>>代码示例>>Java>>正文


Java ViewPager.setCurrentItem方法代码示例

本文整理汇总了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);
}
 
开发者ID:MindorksOpenSource,项目名称:CrashReporter,代码行数:19,代码来源:CrashReporterActivity.java

示例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));

}
 
开发者ID:aliyun,项目名称:aliyun-cloudphotos-android-demo,代码行数:27,代码来源:PreviewActivity.java

示例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);
}
 
开发者ID:oantajames,项目名称:mdb-android-application,代码行数:17,代码来源:MoviesGridActivity.java

示例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);
}
 
开发者ID:KwalaGroup,项目名称:Android-Client,代码行数:19,代码来源:MainActivity.java

示例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);
}
 
开发者ID:Loofer,项目名称:Watermark,代码行数:26,代码来源:MediaPageFragment.java

示例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);
}
 
开发者ID:Ronak-59,项目名称:Trinity-App,代码行数:39,代码来源:ImageViewPager.java

示例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()));
}
 
开发者ID:zaneCC,项目名称:android_permission,代码行数:18,代码来源:FragmentActivity.java

示例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);
}
 
开发者ID:uhuru-mobile,项目名称:mobile-dashboard,代码行数:14,代码来源:DashboardActivity.java

示例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;
        }
    }
}
 
开发者ID:rsippl,项目名称:AndroidProgramming3e,代码行数:34,代码来源:CrimePagerActivity.java

示例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;
        }
    }
}
 
开发者ID:ivicel,项目名称:Android-Programming-BigNerd,代码行数:30,代码来源:CrimePagerActivity.java

示例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);
}
 
开发者ID:LineChen,项目名称:Week_Calendar,代码行数:12,代码来源:WeekCalendar.java

示例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;
        }
    }
}
 
开发者ID:rsippl,项目名称:AndroidProgramming3e,代码行数:34,代码来源:CrimePagerActivity.java

示例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);
}
 
开发者ID:youmi,项目名称:nativead,代码行数:30,代码来源:MainActivity.java

示例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));
    }
}
 
开发者ID:tranleduy2000,项目名称:text_converter,代码行数:28,代码来源:BarcodeEncodedActivity.java

示例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);
}
 
开发者ID:sloiza,项目名称:changApp,代码行数:9,代码来源:MainActivity.java


注:本文中的android.support.v4.view.ViewPager.setCurrentItem方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。