I'm learning about Android and would like to better understand how this part of the system works.
Instead of inflating a layout, would not it be simpler to do as when creating an Activity, such as overwriting the onCreate method and setting up an XML layout?
Example:
public class SampleActivity extends AppCompatActivity {
@Override
protected void onCreate( Bundle savedInstanceState ) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample);
}
}
Here is a part of the code of an example application that can be cloned from github: link
public class FridayFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_friday, container, false);
}
}
Why is inflating necessary? What is his advantage? Thanks for any clarification.