RecyclerView not displaying in Fragment
<p>New to Android, I used the code from
<a href="https://github.com/tutsplus/Android-CardViewRecyclerView" rel="nofollow">https://github.com/tutsplus/Android-CardViewRecyclerView</a>
which is working perfectly.</p>

<p>But when I created Fragment out of it, it is displaying nothing.</p>

<p>CardViewFrag.java</p>

<pre><code>package com.androidatc.customviewindrawer;

import android.app.Activity;
import android.app.Fragment;
import android.net.Uri;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

public class CardViewFrag extends Fragment {

    TextView personName;
    TextView personAge;
    ImageView personPhoto;


    protected void onCreateView(Bundle savedInstanceState) {


        getActivity().setContentView(R.layout.cardview_activity);
        personName = (TextView)getActivity().findViewById(R.id.person_name);
        personAge = (TextView)getActivity().findViewById(R.id.person_age);
        personPhoto = (ImageView)getActivity().findViewById(R.id.person_photo);

        personName.setText("Emma Wilson");
        personAge.setText("23 years old");
        personPhoto.setImageResource(R.drawable.emma);
    }

    public interface OnFragmentInteractionListener {
        // TODO: Update argument type and name
        public void onFragmentInteraction(Uri uri);
    }
}
</code></pre>

<p>RecyclerViewFrag.java</p>

<pre><code>package com.androidatc.customviewindrawer;

import android.app.Activity;
import android.app.Fragment;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class RecyclerViewFrag extends Fragment {

    public List&lt;Person&gt; persons;
    public RecyclerView rv;


    public void onCreateView(Bundle savedInstanceState) {


        getActivity().setContentView(R.layout.recyclerview_activity);

        rv=(RecyclerView)getActivity().findViewById(R.id.rv);

        LinearLayoutManager llm = new LinearLayoutManager(getActivity());
        rv.setLayoutManager(llm);
        rv.setHasFixedSize(true);

        initializeData();
        initializeAdapter();
    }

    public interface OnFragmentInteractionListener {
        // TODO: Update argument type and name
        public void onFragmentInteraction(Uri uri);
    }


    public void initializeData(){
        persons = new ArrayList&lt;&gt;();
        persons.add(new Person("Emma Wilson", "23 years old", R.drawable.emma));
        persons.add(new Person("Lavery Maiss", "25 years old", R.drawable.lavery));
        persons.add(new Person("Lillie Watts", "35 years old", R.drawable.lillie));
    }

    public void initializeAdapter(){
        RVAdapter adapter = new RVAdapter(persons);
        rv.setAdapter(adapter);
    }
}
</code></pre>

<p>RVAdapter.java</p>

<pre><code>package com.androidatc.customviewindrawer;

import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

public class RVAdapter extends RecyclerView.Adapter&lt;RVAdapter.PersonViewHolder&gt; {

    public static class PersonViewHolder extends RecyclerView.ViewHolder {

        CardView cv;
        TextView personName;
        TextView personAge;
        ImageView personPhoto;

        PersonViewHolder(View itemView) {
            super(itemView);
            cv = (CardView)itemView.findViewById(R.id.cv);
            personName = (TextView)itemView.findViewById(R.id.person_name);
            personAge = (TextView)itemView.findViewById(R.id.person_age);
            personPhoto = (ImageView)itemView.findViewById(R.id.person_photo);
        }
    }

    List&lt;Person&gt; persons;

    RVAdapter(List&lt;Person&gt; persons){
        this.persons = persons;
    }

    @Override
    public void onAttachedToRecyclerView(RecyclerView recyclerView) {
        super.onAttachedToRecyclerView(recyclerView);
    }

    @Override
    public PersonViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item, viewGroup, false);
        PersonViewHolder pvh = new PersonViewHolder(v);
        return pvh;
    }

    @Override
    public void onBindViewHolder(PersonViewHolder personViewHolder, int i) {
        personViewHolder.personName.setText(persons.get(i).name);
        personViewHolder.personAge.setText(persons.get(i).age);
        personViewHolder.personPhoto.setImageResource(persons.get(i).photoId);
    }

    @Override
    public int getItemCount() {
        return persons.size();
    }
}
</code></pre>

<p>I am calling this from Navigation drawer.</p>

<pre><code>private void loadFragmentLayout(int position) {
        // update the main content by replacing fragments
        Fragment fragment = null;
        switch (position) {
            case 0:
                fragment = new CardViewFrag();
                break;
            case 1:
                fragment = new BarCodeFrag();
                break;
            case 2:
                fragment = new SearchBookFrag();
                break;
            case 3:
                fragment = new LoginFrag();
                break;
            case 4:
                fragment = new MyAccFrag();
                break;
            default:
                break;
        }
</code></pre>

<p>My MainActivity file is quite big, but every time I add a fragment, I just mention that it implements OnFragmentInteractionListener.  If my Activity is working for all fragments except this one, there should not be any reason - why it is not working for this Frag.    </p>

<p>RecyclerViewFrag.OnFragmentInteractionListener,
        CardViewFrag.OnFragmentInteractionListener</p>

<pre><code>public class MainActivity extends ActionBarActivity
        implements NavigationDrawerFragment.NavigationDrawerCallbacks,
        SearchCatFragment.OnFragmentInteractionListener,
       // AndroidBarcodeQrExample.OnFragmentInteractionListener,
        BarCodeFrag.OnFragmentInteractionListener,
        LoginFrag.OnFragmentInteractionListener,
        HomeFrag.OnFragmentInteractionListener,
        MainViewFragment.OnFragmentInteractionListener,
        SearchBookFrag.OnFragmentInteractionListener,
        SearchBookFragment.OnFragmentInteractionListener,
        MyAccFrag.OnFragmentInteractionListener,
        RecyclerViewFrag.OnFragmentInteractionListener,
        CardViewFrag.OnFragmentInteractionListener
</code></pre>

<p>Any idea - why in Fragment no display?</p>

<p>cardview_activity and recyclerview_activity remain the views without any changes.</p>

<p>cardview_activity.xml</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:padding="16dp"
    &gt;

    &lt;android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/cv"
        &gt;

        &lt;RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="16dp"
            &gt;

            &lt;ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/person_photo"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true"
                android:layout_marginRight="16dp"
                /&gt;

            &lt;TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/person_name"
                android:layout_toRightOf="@+id/person_photo"
                android:layout_alignParentTop="true"
                android:textSize="30sp"
                /&gt;

            &lt;TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/person_age"
                android:layout_toRightOf="@+id/person_photo"
                android:layout_below="@+id/person_name"
                /&gt;

        &lt;/RelativeLayout&gt;

    &lt;/android.support.v7.widget.CardView&gt;

&lt;/LinearLayout&gt;
</code></pre>

<p>recyclerview_activity.xml</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent"
    android:padding="16dp"
    &gt;



    &lt;android.support.v7.widget.RecyclerView
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:id="@+id/rv"
        &gt;

    &lt;/android.support.v7.widget.RecyclerView&gt;


&lt;/LinearLayout&gt;
</code></pre>

<p>This question may be asked a couple of times but none of the solution helped me.</p>

<p>Many thanks.</p>