package com.oreilly.supers;

import android.os.Bundle;
import android.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

public class HeroDetailFragment extends Fragment {
    private long heroId;

    public HeroDetailFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_hero_detail, container, false);
    }

    public void setHeroId(long heroId) {
        this.heroId = heroId;
    }

    @Override
    public void onStart() {
        super.onStart();

        View view = getView();
        if (view != null) {
            TextView heroView = (TextView) view.findViewById(R.id.hero_name);
            TextView secretIdentity = (TextView) view.findViewById(R.id.secret_identity);
            ImageView picture = (ImageView) view.findViewById(R.id.hero_image);

            Hero hero = Hero.HEROES[(int) heroId];
            heroView.setText(hero.getName());
            secretIdentity.setText(hero.getFirst() + " " + hero.getLast());
            picture.setImageResource(hero.getImage());
        }
    }
}

@@ -558,47 +558,110 @@
     
-// Inflate the layout for this fragment
+if (savedInstanceState != null) %7B%0A            heroId = savedInstanceState.getLong(%22heroId%22);%0A        %7D
 %0A   
@@ -1443,11 +1443,176 @@
  %7D%0A    %7D
+%0A%0A    @Override%0A    public void onSaveInstanceState(Bundle outState) %7B%0A        super.onSaveInstanceState(outState);%0A        outState.putLong(%22heroId%22, heroId);%0A    %7D
 %0A%7D%0A

Save heroId in bundle