I am having trouble with my view. Basically I am using Fragment here are my screen shot.  

Photo A
![photo A](https://i.stack.imgur.com/yv5Tq.jpg)
Photo B
![photo B](https://i.stack.imgur.com/oCg8r.jpg)

don't mind the tabs. When I click Setting at upper right of Photo A I inflate the `Settings Layout`
then if I click Account Settings the `Settings Layout` replaced by `Account Detail` layout

after that if I want to logout I will click the Setting but my screen still got the 'Account Detail' page which is the photo B but it must be the `Settings Layout`(photo A)

I don't know how to achieve this. below are my codes.

Settings Button :
Fragment fragment => getFragmentManager().findFragmentById(
 android.R.id.content); if (fragment != null && fragment.isInLayout()) {
 } else {

```
            //fragment
            SharedPreferences.Editor editor = getPreferences(0).edit();
            editor.putString("user_name", user_name);
            editor.putInt("user_id", user_id);
            editor.commit();

            Fragment mFragment = new SettingsFragment();

            FragmentTransaction ft = getFragmentManager()
                    .beginTransaction();
            ft.replace(android.R.id.content, mFragment, "settings");
            ft.commit();

        }

```

in my Fragment:

```
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {      
       if (view != null) {
          ViewGroup parent = (ViewGroup) view.getParent();          //
          System.out.println("asd"+parent);
          if (parent != null) {
        parent.removeView(view);
           }
       } else {

    }
 return view;   
}

```

my Account Setting button :

```
account.setOnClickListener(new View.OnClickListener() {             @Override           public void onClick(View v) {
                Fragment mFragment = new AccountSettings();

                FragmentTransaction ft = getFragmentManager()
                        .beginTransaction();

                ft.replace(R.id.lists, mFragment);

                // ft.addToBackStack(null);
                ft.commit();            }       });

```

Please spare me I'm new to android.Any suggestion and comment would be great help. Thanks