title: onActivityCreated remove layout of Fragment
body: <p>I'm trying to create an application which deals with fragments.
  First, build an application login without using fragments and it worked perfectly, but I tried to be more constructive and create a menu done for me.
  I was trying to migrate all that created the Activity Log for Fragments but I'm having trouble trying to pass everything from a place to another.</p>
  
  <p>What happens to me now is that I have actions that were being created in the OnCreate (Activity) and tried to pass all the functions for onCreateView (Fragments) but when I return from view, is not shown me in app layout that was supposed to.</p>
  
  <p>MainActivity:</p>
  
  <pre><code>import android.content.res.Configuration;
  import android.os.Bundle;
  import android.support.design.widget.NavigationView;
  import android.support.v4.app.Fragment;
  import android.support.v4.app.FragmentManager;
  import android.support.v4.app.FragmentTransaction;
  import android.support.v4.widget.DrawerLayout;
  import android.support.v7.app.ActionBarDrawerToggle;
  import android.support.v7.app.AppCompatActivity;
  import android.support.v7.widget.Toolbar;
  import android.view.Menu;
  import android.view.MenuItem;
  
  public class MainActivity extends AppCompatActivity {
  
      private DrawerLayout mDrawer;
      private Toolbar toolbar;
      private NavigationView nvDrawer;
      private ActionBarDrawerToggle drawerToggle;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          //set tolbar
          toolbar = (Toolbar) findViewById(R.id.toolbar);
          setSupportActionBar(toolbar);
  
          //Find our drawer view
          mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
          drawerToggle = setupDrawerContent();
  
          // Tie DrawerLayout events to the ActionBarToggle
          mDrawer.setDrawerListener(drawerToggle);
  
          // Find our drawer view
          nvDrawer = (NavigationView) findViewById(R.id.nvView);
          // Setup drawer view
          setupDrawerContent(nvDrawer);
  
      }
  
      private ActionBarDrawerToggle setupDrawerContent() {
          return new ActionBarDrawerToggle(this, mDrawer, toolbar, R.string.drawer_open,  R.string.drawer_close);
      }
  
      private void setupDrawerContent(NavigationView navigationView) {
          navigationView.setNavigationItemSelectedListener(
                  new NavigationView.OnNavigationItemSelectedListener() {
                      @Override
                      public boolean onNavigationItemSelected(MenuItem menuItem) {
                          selectDrawerItem(menuItem);
                          return true;
                      }
                  });
  
      }
  
      public void selectDrawerItem(MenuItem menuItem) {
          // Create a new fragment and specify the planet to show based on
          // position
          Fragment fragment = null;
  
          Class fragmentClass = null;
          switch(menuItem.getItemId()) {
              case R.id.nav_first_fragment:
                  fragmentClass = FirstFragment.class;
                  break;
              case R.id.nav_second_fragment:
                  fragmentClass = SecondFragment.class;
                  break;
              case R.id.nav_third_fragment:
                  fragmentClass = ThirdFragment.class;
                  break;
              case R.id.nav_status_fragment:
                  fragmentClass = LoginStatusFragment.class;
                  break;
              case R.id.nav_login_fragment:
                  fragmentClass = LoginFragment.class;
                  break;
              case R.id.nav_register_fragment:
                  fragmentClass = ThirdFragment.class;
                  break;
              default:
                  fragmentClass = FirstFragment.class;
          }
  
          try {
              fragment = (Fragment) fragmentClass.newInstance();
          } catch (Exception e) {
              e.printStackTrace();
          }
  
          // Insert the fragment by replacing any existing fragment
          FragmentManager fragmentManager = getSupportFragmentManager();
          FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
          fragmentTransaction.replace(R.id.flContent, fragment);
          fragmentTransaction.commit();
          //fragmentManager.beginTransaction().replace(R.id.flContent, fragment).commit();
  
          // Highlight the selected item, update the title, and close the drawer
          menuItem.setChecked(true);
          setTitle(menuItem.getTitle());
          mDrawer.closeDrawers();
      }
  
      @Override
      public boolean onOptionsItemSelected(MenuItem item) {
          // The action bar home/up action should open or close the drawer.
          if (drawerToggle.onOptionsItemSelected(item)) {
              return true;
          }
          else if (item.getItemId() == R.id.action_settings) {
              return true;
          }
          return super.onOptionsItemSelected(item);
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }
  
      // Make sure this is the method with just `Bundle` as the signature
      @Override
      protected void onPostCreate(Bundle savedInstanceState) {
          super.onPostCreate(savedInstanceState);
          drawerToggle.syncState();
      }
  
      @Override
      public void onConfigurationChanged(Configuration newConfig) {
          super.onConfigurationChanged(newConfig);
          // Pass any configuration change to the drawer toggles
          drawerToggle.onConfigurationChanged(newConfig);
      }
  
  }
  </code></pre>
  
  <p>LoginStatusFragment:</p>
  
  <pre><code>import android.content.Context;
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.support.v4.app.FragmentManager;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.Button;
  import android.widget.TextView;
  
  import java.util.HashMap;
  
  import helper.SQLiteHandler;
  import helper.SessionManager;
  
  /**
   * Created by NB21094 on 24/11/2015.
   */
  public class LoginStatusFragment extends Fragment {
  
      private TextView txtName;
      private TextView txtEmail;
      private Button btnLogout;
      private Context context;
      private SQLiteHandler db;
      private SessionManager session;
      private View view;
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          // Inflate the layout for this fragment
          view = inflater.inflate(R.layout.activity_loginstatus, container, false);
  
          context = getActivity().getApplicationContext();
  
          txtName = (TextView) view.findViewById(R.id.name);
          txtEmail = (TextView) view.findViewById(R.id.email);
          btnLogout = (Button) view.findViewById(R.id.btnLogout);
  
          // SqLite database handler
          db = new SQLiteHandler(context);
  
          // session manager
          session = new SessionManager(context);
  
          if (!session.isLoggedIn()) {
              logoutUser();
          }
  
          // Fetching user details from sqlite
          HashMap&lt;String, String&gt; user = db.getUserDetails();
  
          String name = user.get("name");
          String email = user.get("email");
  
          // Displaying the user details on the screen
          txtName.setText(name);
          txtEmail.setText(email);
  
          // Logout button click event
          btnLogout.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  logoutUser();
              }
          });
          return view;
          //return inflater.inflate(R.layout.activity_loginstatus, container, false);
      }
         /**
       * Logging out the user. Will set isLoggedIn flag to false in shared
       * preferences Clears the user data from sqlite users table
       * */
      private void logoutUser() {
          session.setLogin(false);
  
          db.deleteUsers();
  
          // Launching the login activity
          /*Intent intent = new Intent(LoginStatusActivity.this, MainActivity.class);
          startActivity(intent);
          finish();*/
          changeFragment("main");
      }
  
      private void changeFragment(String option){
          Fragment fragment = null;
  
          Class fragmentClass = null;
          if(option.contains("loginstatus")){
              fragmentClass = LoginStatusFragment.class;
          } else if (option.contains("register")){
              //fragmentClass = LogoutFragment.class;
          } else if (option.contains("main")) {
              fragmentClass = FirstFragment.class;
          }
  
          try {
              fragment = (Fragment) fragmentClass.newInstance();
          } catch (Exception e) {
              e.printStackTrace();
          }
  
          FragmentManager fragmentManager = getFragmentManager();
          fragmentManager.beginTransaction().replace(R.id.flContent, fragment).commit();
      }
  
  }
  </code></pre>
  
  <p>activity_loginstatus.xml</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;!--&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context="${relativePackage}.${activityClass}" &gt; --&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical" android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:gravity="center_vertical"&gt;
  
      &lt;LinearLayout
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_centerInParent="true"
          android:layout_marginLeft="20dp"
          android:layout_marginRight="20dp"
          android:gravity="center"
          android:orientation="vertical" &gt;
  
          &lt;TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="@string/welcome"
              android:textSize="20dp" /&gt;
  
          &lt;TextView
              android:id="@+id/name"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:padding="10dp"
              android:textColor="@color/lbl_name"
              android:textSize="24dp" /&gt;
  
          &lt;TextView
              android:id="@+id/email"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:textSize="13dp" /&gt;
  
          &lt;Button
              android:id="@+id/btnLogout"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_marginTop="40dip"
              android:background="@color/btn_logut_bg"
              android:text="@string/btn_logout"
              android:textAllCaps="false"
              android:textColor="@color/white"
              android:textSize="15dp" /&gt;
      &lt;/LinearLayout&gt;
  &lt;/LinearLayout&gt;
  &lt;!-- &lt;/RelativeLayout&gt; --&gt;
  </code></pre>
  
  <p>Can you please help me?
  The layout never appear and i dont know why.</p>