FragmentTransaction.attachは、FragmentTransaction.detachとは逆に、FragmentとViewを再び紐づける。
FragmentTransaction | Android Developers
まあ、Viewの再生成だよね。
activity_main.xmlで、
Buttonを3つに増やしている。
(strings.xmlはもう省略。)
MainActivity.javaで、
Button3でattachしている。
![f:id:BG1:20201020141027p:plain 起動時](https://cdn-ak.f.st-hatena.com/images/fotolife/B/BG1/20201020/20201020141027.png)
起動時。
![f:id:BG1:20201020141104p:plain onCreateViewなのでView生成](https://cdn-ak.f.st-hatena.com/images/fotolife/B/BG1/20201020/20201020141104.png)
onCreateViewなのでView生成。
![f:id:BG1:20201020141152p:plain この時点でButton2押したら、viewはnullではない。](https://cdn-ak.f.st-hatena.com/images/fotolife/B/BG1/20201020/20201020141152.png)
この時点でButton2押したら、viewはnullではない。
![f:id:BG1:20201020141230p:plain Button1でdetach](https://cdn-ak.f.st-hatena.com/images/fotolife/B/BG1/20201020/20201020141230.png)
Button1でdetach。
TextViewが消えてます。
![f:id:BG1:20201020141317p:plain onDestroyViewだけ](https://cdn-ak.f.st-hatena.com/images/fotolife/B/BG1/20201020/20201020141317.png)
onDestroyViewだけ。
![f:id:BG1:20201020141347p:plain Button2を押して、nullになってるのも確認。](https://cdn-ak.f.st-hatena.com/images/fotolife/B/BG1/20201020/20201020141347.png)
Button2を押して、nullになってるのも確認。
![f:id:BG1:20201020141422p:plain Button3を押すと、Fragment1のViewであるTextView"Fragment1"が復活。](https://cdn-ak.f.st-hatena.com/images/fotolife/B/BG1/20201020/20201020141422.png)
Button3を押すと、Fragment1のViewであるTextView"Fragment1"が復活。
![f:id:BG1:20201020141554p:plain またonCreateViewが呼ばれている。](https://cdn-ak.f.st-hatena.com/images/fotolife/B/BG1/20201020/20201020141554.png)
またonCreateViewが呼ばれている。
![f:id:BG1:20201020141633p:plain Button2でviewがnullでないのも確認した](https://cdn-ak.f.st-hatena.com/images/fotolife/B/BG1/20201020/20201020141633.png)
Button2でviewがnullでないのも確認した。