title: Fragment Changes when Screen is rotated
body: <p>I have two fragments, FragmentCity and Fragmentnumber1. When screen orientation changes on fragmentnumber1, it goes back to FragmentCity. Does anyone know how to solve this? I appreciate it if you could show me how to solve this issue</p>
  
  <p>FragmentCity</p>
  
  <pre><code>public class FragmentCity extends Fragment {
  
      final String[] items = new String[]{"FC1", "FC2", "FC3", "FC4","FC5"
      };
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
  
          View view = inflater.inflate(R.layout.haz, container, false);
  
          ListView list = (ListView) view.findViewById(R.id.fir);
          ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(getActivity(), android.R.layout.simple_list_item_1, items);
          list.setAdapter(adapter);
  
          list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
              @Override
              public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int arg2,
                                      long arg3) {
  
                  Fragment myFragment = null;
  
                  switch (arg2) {
  
                      case 0:
                          myFragment = new Fragmentnumber1();
                          break;
                      case 1:
                          myFragment = new Fragmentnumber2();
                          break;
                      case 2:
  
                          myFragment = new Fragmentnumber3();
                          break;
                      case 3:
                          myFragment = new Fragmentnumber4();
                          break;
                      case 4:
                          myFragment = new Fragmentnumber5();
  
                          break;
  
                  }
                  // update the main content by replacing fragments
  
                  FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
                  fragmentManager.popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
                  fragmentManager.beginTransaction().addToBackStack("frag")
                          .replace(R.id.container2, myFragment)
                          .commit();
  
  
              }
  
          });
          return view;
      }
  
  
  
  }
  </code></pre>
  
  <p>Fragmentnumber1</p>
  
  <pre><code>public class Fragmentnumber1 extends Fragment {
  
      final String[] items = new String[]{"num1", "num2", "num3"
      };
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
  
          View view = inflater.inflate(R.layout.haz, container, false);
  
          ListView list = (ListView) view.findViewById(R.id.fir);
          ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(getActivity(), android.R.layout.simple_list_item_1, items);
          list.setAdapter(adapter);
  
          list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
              @Override
              public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int arg2,
                                      long arg3) {
  
                  Fragment myFragment = null;
                  switch (arg2){
                      case 0:
                          myFragment = new num1();
                          break;
                      case 1:
                          myFragment = new num2();
                          break;
                      case 2:
                          myFragment = new num3();
                          break;
  
                  }
                  // update the main content by replacing fragments
                  FragmentManager fragmentManager = getChildFragmentManager();
                  fragmentManager.beginTransaction().addToBackStack(null)
                          .replace(R.id.container2, myFragment)
                          .commit();
              }
  
          });
          return view;
      }
  
  
  
  
  }
  </code></pre>