Change Fragment layout on orientation
<p>I need a solution! error in addView() i don´t know the answer.....</p>

<p>I want to change the layout, using the previous views</p>

<p>i need help!</p>

<p>chart ---- <a href="https://github.com/PhilJay/MPAndroidChart" rel="nofollow">https://github.com/PhilJay/MPAndroidChart</a></p>

<p>Process: com.example.tiago.alsrm_android, PID: 23337
                                                                                 java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
                                                                                     at android.view.ViewGroup.addViewInner(ViewGroup.java:3784)
                                                                                     at android.view.ViewGroup.addView(ViewGroup.java:3637)
                                                                                     at android.view.ViewGroup.addView(ViewGroup.java:3582)
                                                                                     at android.view.ViewGroup.addView(ViewGroup.java:3558)
                                                                                     at com.example.tiago.alsrm_android.Fragment.EDA_Fragment.onConfigurationChanged(EDA_Fragment.java:174)</p>

<p>public class EDA_Fragment extends Fragment {</p>

<pre><code>private Intent intentService;
private Chart chart = null;
private View fragmentRootContainer;

@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    if(fragmentRootContainer == null) {
        fragmentRootContainer = inflater.inflate(R.layout.activity_exam, container, false);

        if (chart == null)
            chart = new Chart((LineChart) fragmentRootContainer.findViewById(R.id.chart), EDA, 1023f, 1f);


    return fragmentRootContainer;
}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    setRetainInstance(true);
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);

    LayoutInflater inflater = LayoutInflater.from(getActivity());
    ViewGroup viewGroup = (ViewGroup) getView();
    viewGroup.removeAllViewsInLayout();

    // Checks the orientation of the screen
    if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {

        View view = inflater.inflate(R.layout.activity_exam, null);

        LineChart lineChart = (LineChart)view.findViewById(R.id.chart);
        lineChart.addView(chart.getChart());


    } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT){

        View view = inflater.inflate(R.layout.activity_exam, null);

        LineChart lineChart = (LineChart)view.findViewById(R.id.chart);
        lineChart.addView(chart.getChart());

    }
}
</code></pre>

<p>}</p>