title: Instantiate Fragment dynamically by class name
body: <p>I have a main activity with a menu to navigate through the page. To dynamize my code, I created my adapter with the name and the class of all of my fragments.</p>
  
  <pre><code>public class MenuItem {
  
      private String title;
      private Class className;
      ...
  }
  </code></pre>
  
  <p>I have my adapter created that way : </p>
  
  <pre><code>    ArrayList&lt;MenuItem&gt; menuItems=new ArrayList&lt;MenuItem&gt;();
  
      menuItems.add(new MenuItem("Home", null, HomeFragment.class, R.drawable.ic_drawer, true));
      menuItems.add(new MenuItem("Schedule", null, ScheduleFragment.class, R.drawable.ic_drawer, false));
  </code></pre>
  
  <p>In my menu onClickListener, I want to directly open the page without doing any conditional statement :</p>
  
  <pre><code>private AdapterView.OnItemClickListener mItemClickListener = new AdapterView.OnItemClickListener() {
      @Override
      public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
  
          Class c =  ((MenuItem) mMenuAdapter.getItem(position)).getClassName();
          Fragment fragment = ??? //How do I create a Fragment dynamically ? 
  
          FragmentManager fragmentManager = getFragmentManager();
          fragmentManager.beginTransaction().replace(R.id.fl_container, fragment).commit();
  </code></pre>
  
  <p>This way of coding is used for the Activity, but it's simpler in that case because to change an activity, we're using only startActivity with the name of the activity, not its instance.</p>
  
  <p>Do I need to use reflection ?</p>