How to insert existing fragment to Mortar architecture

114 Views Asked by At

Let's consider this situation. We are building an app using Mortar and Flow to simplify things and then all of the sudden we see that we can use some of the old fragments. This fragments are a little bit complex so we would like to somehow inject them to our Views.

Would that be possible if we have our Mortar View like this:

<?xml version="1.0" encoding="utf-8"?>
<com.foo.myMortarView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="+id/mortar_view"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:baselineAligned="false"
    android:orientation="horizontal" >

    <fragment
        android:id="@+id/myFragment"
        android:layout_width="0dp"
        android:layout_weight="2"
        android:layout_height="match_parent"
        class="com.example.MyFragment" >
    </fragment>

</com.foo.myMortarView>

And our Fragment like this:

public class MyFragment extends Fragment{
   @Override
   public View onCreateView(LayoutInflater inflater,
      ViewGroup container, Bundle savedInstanceState) {
      /**
       * Inflate the layout for this fragment
       */
      return inflater.inflate(
      R.layout.my_fragment, container, false);
   }
} 

This of course doesn't work out of the box so how can we accomplish that? Thanks!

0

There are 0 best solutions below