android_learning:headfirst_android_development_notes:chapter_7
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
android_learning:headfirst_android_development_notes:chapter_7 [2016/02/12 23:17] – [p. 274: Project setup] mithat | android_learning:headfirst_android_development_notes:chapter_7 [2016/02/21 03:33] (current) – mithat | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | <WRAP center round info 60%> | + | ====== Chapter 7 ====== |
- | Under development. | + | |
- | </ | + | |
- | + | ||
- | ====== Chapter 7 notes ====== | + | |
There' | There' | ||
Line 16: | Line 12: | ||
<WRAP center round tip 90%> | <WRAP center round tip 90%> | ||
In an Android Studio' | In an Android Studio' | ||
+ | {{: | ||
</ | </ | ||
===== p. 275: Code block ===== | ===== p. 275: Code block ===== | ||
Line 269: | Line 266: | ||
</ | </ | ||
- | This seems perfectly sensible, and if you run it it seems to work fine. But if you try to click the " | + | This seems perfectly sensible, and if you run it it seems to work fine. But if you try to click the " |
- | <WRAP center round todo 60%> | + | |
- | Make and embed video | + | |
- | </ | + | |
The user's expected behavior is for the back button to show the previously selected details. But the back button' | The user's expected behavior is for the back button to show the previously selected details. But the back button' | ||
Line 351: | Line 345: | ||
===== p 316 ===== | ===== p 316 ===== | ||
- | If you try to run the app on a phone-sized device or emulator at this point, it will crash when you click on one of the activities. Can you explain why? | + | If you try to run the app on a phone-sized device or emulator at this point, it will crash when you click on one of the activities. Can you explain why? (The answer should be clear after you examine the code on p. 321.) |
+ | |||
+ | ===== p. 319: Code block ===== | ||
+ | Note that '' | ||
+ | |||
+ | <file java DetailActivity.java> | ||
+ | package com.hfad.workout; | ||
+ | |||
+ | import android.app.Activity; | ||
+ | import android.os.Bundle; | ||
+ | |||
+ | public class DetailActivity extends Activity { | ||
+ | public static final String EXTRA_WORKOUT_ID = " | ||
+ | |||
+ | @Override | ||
+ | protected void onCreate(Bundle savedInstanceState) { | ||
+ | super.onCreate(savedInstanceState); | ||
+ | setContentView(R.layout.activity_detail); | ||
+ | WorkoutDetailFragment workoutDetailFragment = (WorkoutDetailFragment) | ||
+ | getFragmentManager().findFragmentById(R.id.detail_frag); | ||
+ | int workoutId = (int) getIntent().getExtras().get(EXTRA_WORKOUT_ID); | ||
+ | workoutDetailFragment.setWorkoutId(workoutId); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== p. 321 ===== | ||
+ | |||
+ | Here's the '' | ||
+ | |||
+ | <file java MainActivity.java> | ||
+ | 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' | ||
+ | details.setWorkoutId(id); | ||
+ | |||
+ | // Call up the fragment manager and do a new transaction. | ||
+ | getFragmentManager().beginTransaction() | ||
+ | .replace(R.id.fragment_container, | ||
+ | .addToBackStack(null) | ||
+ | .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE) | ||
+ | .commit(); | ||
+ | } | ||
+ | else { | ||
+ | // Create an intent to launch a DetailActivity | ||
+ | Intent intent = new Intent(this, | ||
+ | intent.putExtra(DetailActivity.EXTRA_WORKOUT_ID, | ||
+ | startActivity(intent); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | </ |
android_learning/headfirst_android_development_notes/chapter_7.1455319052.txt.gz · Last modified: 2016/02/12 23:17 by mithat