title: I need to create a first and last button for my ViewPager
body: <p>Hello need help with a class trying to figure out how to create a first and last button in a fragment that will jump to the first item in a ViewPager and the last item in a ViewPager I'm a bit lost with how to implement. Here is the fragment. </p>
  
  <pre><code>public class CrimeFragment extends Fragment {
  
  private static final String ARG_CRIME_ID = "crime_id";
  private static final String DIALOG_DATE = "DialogDate";
  private static final int REQUEST_DATE = 0;
  
  private Crime mCrime;
  private EditText mTitleField;
  private Button mDateButton;
  private CheckBox mSolvedCheckBox;
  private Spinner mSpinner;
  private Button mFirstButton;
  private Button mLastButton;
  
  
  public static CrimeFragment newInstance(UUID crimeId) {
      Bundle args = new Bundle();
      args.putSerializable(ARG_CRIME_ID, crimeId);
  
      CrimeFragment fragment = new CrimeFragment();
      fragment.setArguments(args);
      return fragment;
  }
  
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
      if (resultCode != Activity.RESULT_OK) {
          return;
      }
      if (requestCode == REQUEST_DATE) {
          Date date =
                  (Date) data.getSerializableExtra(DatePickerFragment.EXTRA_DATE);
          mCrime.setDate(date);
          updateDate();
      }
  }
  
  private void updateDate() {
      mDateButton.setText(mCrime.getDate().toString());
  }
  
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      UUID crimeId = (UUID) getArguments().getSerializable(ARG_CRIME_ID);
      mCrime = CrimeLab.get(getActivity()).getCrime(crimeId);
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      View v = inflater.inflate(R.layout.fragment_crime, container, false);
  
      mTitleField = (EditText)v.findViewById(R.id.crime_title);
      mTitleField.setText(mCrime.getTitle());
      mTitleField.addTextChangedListener(new TextWatcher() {
          @Override
          public void beforeTextChanged(
              CharSequence s, int start, int count, int after) {
  
          }
          @Override
          public void onTextChanged(
              CharSequence s, int start, int before, int count) {
  
          }
  
          @Override
          public void afterTextChanged(Editable s) {
  
          }
      });
  
      mDateButton = (Button) v.findViewById(R.id.crime_date);
      updateDate();
      mDateButton.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              FragmentManager manager = getFragmentManager();
              DatePickerFragment dialog = DatePickerFragment.newInstance(mCrime.getDate());
              dialog.setTargetFragment(CrimeFragment.this, REQUEST_DATE);
              dialog.show(manager, DIALOG_DATE);
          }
      });
  
      mSpinner = (Spinner) v.findViewById(R.id.crime_severity);
      ArrayAdapter&lt;CharSequence&gt; adapter = ArrayAdapter.createFromResource(this.getActivity(),
              R.array.severity_array, android.R.layout.simple_spinner_item);
      adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
      mSpinner.setAdapter(adapter);
  
      mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
          @Override
          public void onItemSelected(AdapterView&lt;?&gt; parentView, View selectedItemView, int position, long id) {
              mCrime.setSeverity((String) mSpinner.getSelectedItem());
          }
  
          @Override
          public void onNothingSelected(AdapterView&lt;?&gt; parentView) {
  
          }
      });
  
      mSolvedCheckBox = (CheckBox) v.findViewById(R.id.crime_solved);
      mSolvedCheckBox.setChecked(mCrime.isSolved());
      mSolvedCheckBox.setOnCheckedChangeListener(
              new CompoundButton.OnCheckedChangeListener() {
                  @Override
                  public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
                      mCrime.setSolved(isChecked);
                  }
      });
  
      mFirstButton = (Button) v.findViewById(R.id.first_crime_button);
      mFirstButton.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
  
          }
      });
  
      mLastButton = (Button) v.findViewById(R.id.last_crime_button);
      mLastButton.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
  
          }
      });
  
  
  
  
      return v;
  }
  
  }
  </code></pre>
  
  <p>Here is the Activity with the ViewPager.</p>
  
  <pre><code>public class CrimePagerActivity extends FragmentActivity{
  
  private static final String EXTRA_CRIME_ID =   "com.martin.android.criminalintent.crime_id";
  
  private ViewPager mViewPager;
  private List&lt;Crime&gt; mCrimes;
  
  
  public static Intent newIntent(Context packageContext, UUID crimeId) {
      Intent intent = new Intent(packageContext, CrimePagerActivity.class);
      intent.putExtra(EXTRA_CRIME_ID, crimeId);
      return intent;
  }
  
  @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.activity_crime_pager_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 &lt; mCrimes.size(); i++) {
          if (mCrimes.get(i).getId().equals(crimeId)) {
              mViewPager.setCurrentItem(i);
              break;
          }
      }
  }
  }
  </code></pre>
  
  <p>For the First button Im pretty sure I just need to set item to 0? For last button I need to set item to size - 1 just not sure how to do that.</p>