public static CrimeFragment newInstance(UUID crimeId) { Bundle args = new Bundle(); args.putSerializable(EXTRA_CRIME_ID, crimeId); CrimeFragment fragment = new CrimeFragment(); fragment.setArguments(args); return fragment; }
@Override protected Fragment createFragment() { // return new CrimeFragment(); Calling the CrimeFragment constructor directly // Retrieve the UUID from CrimeFragment UUID crimeId = (UUID) getIntent().getSerializableExtra(CrimeFragment.EXTRA_CRIME_ID); return CrimeFragment.newInstance(crimeId); // Activities need to know about their fragments, not vice versa }
@Override public void onCrimeSelected(Crime crime) { if (findViewById(R.id.detail_fragment_container) == null) { Intent pagerIntent = CrimePagerActivity.newIntent(CrimeListActivity.this, crime.getId()); startActivity(pagerIntent); } else { Fragment newDetail = CrimeFragment.newInstance(crime.getId()); getSupportFragmentManager() .beginTransaction() .replace(R.id.detail_fragment_container, newDetail) .commit(); } }