title: Using RecyclerView with Fragments
body: <p>I built the RecycleView widget with CardView from this tutorial: </p>
  
  <p><a href="http://www.treyrobinson.net/blog/android-l-tutorials-part-3-recyclerview-and-cardview/" rel="noreferrer">Android L Tutorials (Part 3) - RecyclerView and CardView</a></p>
  
  <p>Now Im trying to show it as a Fragment.</p>
  
  <p>Here is my FragmentActivity:</p>
  
  <pre><code>public class FragmentActivity extends Fragment {  
      private RecyclerView mRecyclerView;
      private CountryAdapter mAdapter;
      private LinearLayoutManager layoutManager;
      public FragmentActivity(){}
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          View rootView = inflater.inflate(R.layout.card_layout, container, false);
          mRecyclerView = (RecyclerView) rootView.findViewById(R.id.list);
          layoutManager = new LinearLayoutManager(getActivity());
          mRecyclerView.setLayoutManager(layoutManager);
          mRecyclerView.setAdapter(mAdapter);
          mAdapter = new CountryAdapter(CountryManager.getInstance().getCountries(), R.layout.card_layout, getActivity());
          return rootView;
      }
      @Override
      public void onActivityCreated(Bundle savedInstanceState) {
          super.onActivityCreated(savedInstanceState);
      }
  }
  </code></pre>
  
  <p>MainActivity where I call my fragment:
  public class MainActivity extends Activity {</p>
  
  <pre><code>@Override
  protected void onCreate(Bundle savedInstanceState) {
  
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      FragmentActivity fragment = new FragmentActivity();
      FragmentManager fragmentManager = getFragmentManager();
      fragmentManager.beginTransaction()
              .add(R.id.container_list, fragment).commit();
  }
  </code></pre>
  
  <p>Here is my activity_main layout:</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  xmlns:tools="http://schemas.android.com/tools"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  tools:context=".CountryActivity"&gt;
      &lt;android.support.v7.widget.RecyclerView
          android:id="@+id/list"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          tools:context=".CountryActivity"
          /&gt;
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>My card_layout</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="horizontal" android:layout_width="match_parent"
      xmlns:card_view="http://schemas.android.com/apk/res-auto"
      android:layout_margin="5dp"
      card_view:cardCornerRadius="5dp"
      android:layout_height="match_parent"&gt;
  
      &lt;RelativeLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"&gt;
  
          &lt;ImageView
              android:id="@+id/countryImage"
              android:layout_width="match_parent"
              android:layout_height="100dp"
              android:scaleType="centerCrop"
              android:tint="@color/photo_tint"
              android:layout_centerInParent="true"
              /&gt;
  
          &lt;TextView
              android:id="@+id/countryName"
              android:gravity="center"
              android:background="?android:selectableItemBackground"
              android:focusable="true"
              android:clickable="true"
              android:layout_width="match_parent"
             android:layout_height="100dp"
             android:textSize="24sp"
             android:layout_centerInParent="true"
             android:textColor="@android:color/white"
             /&gt;
  
      &lt;/RelativeLayout&gt;
  &lt;/android.support.v7.widget.CardView&gt;
  </code></pre>
  
  <p>and frame_layout :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
               android:layout_width="match_parent"
               android:layout_height="match_parent"
               android:id="@+id/container_list"&gt;
  
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p>The app crashes when it calls the fragment.
  Your help will be appreciated guys.</p>