User Tools

Site Tools


android_learning:headfirst_android_development_notes:chapter_7

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
android_learning:headfirst_android_development_notes:chapter_7 [2016/02/12 23:43] – [p 316] mithatandroid_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. +
-</WRAP> +
- +
-====== Chapter 7 notes ======+
  
 There's a //lot// of new stuff in this chapter, so you may want to set aside extra time. There's a //lot// of new stuff in this chapter, so you may want to set aside extra time.
Line 270: Line 266:
 </code> </code>
  
-This seems perfectly sensible, and if you run it it seems to work fine. But if you try to click the "back" button+This seems perfectly sensible, and if you run it it seems to work fine. But if you try to click the "back" button, you have problems.
-<WRAP center round todo 60%> +
-Make and embed video +
-</WRAP>+
  
 The user's expected behavior is for the back button to show the previously selected details. But the back button's default behavior is to show the previous Activity or the home screen if there is none---and fragments are not activities. Thus, the need to push fragment changes onto the //back stack// using //format transactions//. The user's expected behavior is for the back button to show the previously selected details. But the back button's default behavior is to show the previous Activity or the home screen if there is none---and fragments are not activities. Thus, the need to push fragment changes onto the //back stack// using //format transactions//.
Line 374: Line 367:
         int workoutId = (int) getIntent().getExtras().get(EXTRA_WORKOUT_ID);         int workoutId = (int) getIntent().getExtras().get(EXTRA_WORKOUT_ID);
         workoutDetailFragment.setWorkoutId(workoutId);         workoutDetailFragment.setWorkoutId(workoutId);
 +    }
 +}
 +</file>
 +
 +===== p. 321 =====
 +
 +Here's the ''MainActivity'' code with some comments thrown in and some code that's not needed taken out.
 +
 +<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'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);
 +        }
     }     }
 } }
 </file> </file>
android_learning/headfirst_android_development_notes/chapter_7.1455320634.txt.gz · Last modified: 2016/02/12 23:43 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki