title: Fragment on Button Click Open Activity Load it with Fragment
body: <p><strong>Image below is want I want</strong></p>
  
  <p><a href="https://i.stack.imgur.com/EaGCq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EaGCq.png" alt="enter image description here"></a></p>
  
  <blockquote>
    <p>The <code>MainActivity</code> has a Fragment, in which there are 3 Buttons.</p>
    
    <p>On Click of Button the Container should load the particular Fragment </p>
    
    <p><code>ContainerActivity</code> should load the <code>Fragment</code></p>
    
    <p>i have created three fragment
    studyfragment, mathsfragment, sciencefragment</p>
  </blockquote>
  
  <p>I have tried below code, but not working.</p>
  
  <pre><code>View view = inflater.inflate(R.layout.fragment_first, container, false);
  Button btn = (Button)view.findViewById(R.id.button1);
  btn.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
  
          Intent intent = new Intent(First.this.getActivity(),Container.class);
          startActivity(intent);
  
          Second second = new Second();
          FragmentTransaction transaction = getFragmentManager().beginTransaction();
          transaction.replace(R.id.cont,second).addToBackStack(null).commit();
      }
  });
  </code></pre>