Layout duplicating itself on screen rotation

You can also setRetainedInstance(true) on your fragment, then try to get the Fragment form de FragmentManager.findFragmentById(int) or FragmentManager.findFragmentByTag(String), and if it returns null it meant you had to create a new instance of your Fragment.

private FileDetails fileDetailsFragment; 


public void onCreate(Bundle savedInstanceState) {
...
    FragmentManager fragmentManager = getSupportFragmentManager();
    fileDetailsFragment = (FileDetails) getSupportFragmentManager().findFragmentById(R.id.DetailsHolder);
    if (fileDetailsFragment == null) {
        fileDetailsFragment = new FileDetails(FileData); 
    }

    FragmentTransaction fragmentTransaction = fragmentManager
            .beginTransaction();

    fragmentTransaction.add(R.id.DetailsHolder, fileDetailsFragment);
    fragmentTransaction.commit();
}

Fixed it!

Turns out it wasn't the view duplicating itself, or the EditText, or the Button. It was the entire fragment.

In my Activity's onCreate, I add the fragment to an xml layout:

private FileDetails fileDetailsFragment;

public void onCreate(Bundle savedInstanceState) {
        ...
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager
                .beginTransaction();
        fileDetailsFragment = new FileDetails(fileData);
        fragmentTransaction.add(R.id.DetailsHolder, fileDetailsFragment);
        fragmentTransaction.commit();

And onCreate was being called every time I rotated the phone (as it's meant to). So I put in a check to see if the activity is being run for the first time, and it works great.

private FileDetails fileDetailsFragment;

public void onCreate(Bundle savedInstanceState) {
    ...
    if (savedInstanceState == null) {
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager
                .beginTransaction();
        fileDetailsFragment = new FileDetails(fileData);
        fragmentTransaction.add(R.id.DetailsHolder, fileDetailsFragment);
        fragmentTransaction.commit();
    } else {
        fileDetailsFragment = (FileDetails) getSupportFragmentManager().findFragmentById(R.id.DetailsHolder);
    }