Create different fragment types by one function
<p>I need a function in my Activity, that sets fragment to my ViewGroup (FrameLayout in this case). Of course, I can use such construction:</p>

<pre><code>public void setFragment(Fragment fragment){
    FragmentManager fm=getFragmentManager();
    //etc
}
</code></pre>

<p>But with this solution I need to create <code>fragment</code> somewhere else, not in my function. So, if class <code>MyFragment</code> extends <code>Fragment</code>, I need something like this:</p>

<pre><code>setFragment(MyFragment);
</code></pre>

<p>Is it possible? <strong>Can I pass class as a parameter of function and then create instance of it</strong></p>

<p>And if it's not - is it a bad idea to create fragment behind the function? Like</p>

<pre><code>MyFragment my=new MyFragment();
setFragment(my);
</code></pre>
