Our first Fragment app
Let's build Fragment
in its simplest possible form so we can understand what is going on before, in later chapters, we start producing Fragments all over the place that are of genuine usefulness.
Note
I urge all readers to go through and build this project. There is a lot of jumping around from file to file and just reading alone can make it seem more complex than it really is. Certainly, you can copy and paste the code from the download bundle but please also follow the steps and create your own projects and classes. Fragments are not too tough but their implementation, as their name suggests, is a little fragmented.
Create a new project called Simple Fragment
using the Empty Activity template and leaving the rest of the settings at their defaults.
Switch to activity_main.xml
and delete the default Hello world! TextView
widget.
Now make sure the root ConstraintLayout
is selected by left-clicking it in the Component tree window, then change...