Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PlaceholderFragment in Android

I'm creating a new Android Project in Eclipse and I'm only using SDK version 19 (Android 4.4). I did the same thing a few weeks ago but today I noticed a difference. There is an automatiacally generated inner class in my MainActivity :

/**
 * A placeholder fragment containing a simple view.
 */
public static class PlaceholderFragment extends Fragment {

    public PlaceholderFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_main, container,
                false);
        return rootView;
    }
}

I've been trying to find documentation on this but I can't find anything. Is there a reason for this? Following guidelines should everything be a Fragment now?

like image 410
Ryan Sayles Avatar asked Apr 23 '14 00:04

Ryan Sayles


People also ask

What are Android Fragments?

According to the Android documentation, a fragment is a part of applications user interface that is bound to an activity. Fragments have their lifecycle and layouts or UI components. Fragments help enrich your UI design, pass data between different screens, and adapt to different device configurations.

How many ways to call Fragment?

There are 12 lifecycle methods for fragment.


2 Answers

Yes creating new android project now creates appcompat version 7 lib with it. And activities are changed to activities containing fragment . From now on ui is to be handeled from Placeholder fragment. This new imrovement has an advantage as it supports action bar for older versions for 7.

like image 93
Gautami Avatar answered Oct 06 '22 00:10

Gautami


It looks like they are wanting people to use Fragments for the content view of the activities now instead of setting it to the activity itself. They are trying to set forth a standard pattern.

This is fine by me, as I already use fragments this way :), though not as an inner class. That just gets messy.

like image 24
WIllJBD Avatar answered Oct 05 '22 23:10

WIllJBD