Back to project page Android-CriminalIntent.
The source code is released under:
MIT License
If you think the Android project Android-CriminalIntent listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.bignerdranch.android.criminalintent; //from www . j a v a2 s .c o m import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentStatePagerAdapter; import android.support.v4.view.ViewPager; import java.util.ArrayList; import java.util.UUID; /** * ViewPager Activity * Created by mweekes on 12/21/13. */ public class CrimePagerActivity extends FragmentActivity { private ViewPager mViewPager; private ArrayList<Crime> mCrimes; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mViewPager = new ViewPager(this); mViewPager.setId(R.id.viewPager); setContentView(mViewPager); mCrimes = CrimeLab.get(this).getCrimes(); FragmentManager fm = getSupportFragmentManager(); mViewPager.setAdapter(new FragmentStatePagerAdapter(fm) { @Override public Fragment getItem(int i) { Crime crime = mCrimes.get(i); return CrimeFragment.newInstance(crime.getId()); } @Override public int getCount() { return mCrimes.size(); } }); UUID crimeId = (UUID) getIntent().getSerializableExtra(CrimeFragment.EXTRA_CRIME_ID); for (int i = 0; i < mCrimes.size(); i++) { if (mCrimes.get(i).getId().equals(crimeId)) { mViewPager.setCurrentItem(i); break; } } mViewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int i, float v, int i2) { } @Override public void onPageSelected(int i) { Crime crime = mCrimes.get(i); if (crime.getTitle() != null) { setTitle(crime.getTitle()); } } @Override public void onPageScrollStateChanged(int i) { } }); } }