title: Add fragment from ViewModel in MVVM architecture
body: <p>I am using <code>DataBinding</code> and following <strong>MVVM architecture</strong>, now i am stuck on how to add new fragment from <code>ViewModel</code> as we need defined click event on <code>ViewModel</code>. Here is my <code>MainViewModel</code> class</p>
  
  <pre><code>public class MainViewModel {
      private Context context;
  
      public MainViewModel (Context context) {
          this.context = context;
      }
      public void onClick(View v) {
  
      }
  }
  </code></pre>
  
  <p>here is my xml where i have defined click event</p>
  
  <pre><code>&lt;layout xmlns:android="http://schemas.android.com/apk/res/android"&gt;
  
      &lt;data&gt;
          &lt;variable
              name="viewmodel"
              type="com.example.MainViewModel" /&gt;
      &lt;/data&gt;
  
      &lt;RelativeLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"&gt;
           &lt;TextView
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:onClick="@{viewmodel::onClick}"
              android:text="click me"/&gt;
      &lt;/RelativeLayout&gt;
  &lt;/layout&gt;
  </code></pre>
  
  <p>now how can i get <code>supportFragmentManager</code> or <code>childFragmentManager</code> from my ViewModel class? I have tried to use <code>activity.getSupportFragmentManager()</code> and <code>activity.getChildFragmentManager()</code> but it doesn't have that kind of method.</p>
  
  <p>I know we can add fragment with following code</p>
  
  <pre><code>getActivity().getSupportFragmentManager().beginTransaction()
              .setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out, android.R.anim.fade_in, android.R.anim.fade_out).
              add(R.id.container, fragment, "").addToBackStack("main").commit();
  </code></pre>
  
  <p>but how to do it in <code>ViewModel</code> class</p>