package com.hfad.workout; import android.app.FragmentTransaction; import android.app.Activity; import android.content.Intent; import android.os.Bundle; public class MainActivity extends Activity implements WorkoutListListener { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public void itemClicked(long id) { // Check to see if we have a fragment_container // ... if we do, then we're on a large screen. if (findViewById(R.id.fragment_container) != null) { // Create a new WorkoutDetailFragment to replace the previous one. WorkoutDetailFragment details = new WorkoutDetailFragment(); // Set the new fragment's properties. details.setWorkoutId(id); // Call up the fragment manager and do a new transaction. getFragmentManager().beginTransaction() .replace(R.id.fragment_container, details) .addToBackStack(null) .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE) .commit(); } else { // Create an intent to launch a DetailActivity Intent intent = new Intent(this, DetailActivity.class); intent.putExtra(DetailActivity.EXTRA_WORKOUT_ID, (int) id); startActivity(intent); } } }