Embedding a RecyclerView within a custom view
<p>I am trying to embed a <code>RecyclerView</code> within the body of a custom view (a <code>RefreshableList</code>).</p>

<p>This is my project's structure: it contains 2 modules, <strong>app</strong> &amp; <strong>rlist</strong>. </p>

<p><a href="https://i.stack.imgur.com/xtwQ6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xtwQ6.png" alt="Project view"></a></p>

<p>the <strong>rlist</strong> module holds the custom view (<code>RefreshableList</code>) in which I want to embed a <code>RecyclerView</code>.</p>

<p><strong>RefreshableList.java</strong> (The custom view)</p>

<pre><code>public class RefreshableList extends RelativeLayout {

    private RecyclerView mRecyclerView;

    private Context mContext;
    private MyAdapter mAdapter;

    public RefreshableList(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContext = context;
        Log.i("ADAPTER", "RefreshableList is initializing views...");

        setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));

        LayoutInflater inflater = (LayoutInflater) context.getSystemService(
                Context.LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.refreshable_list, null);

        findViewsById(view);
        setupRecyclerView();
    }

    private void findViewsById(View view) {
        mRecyclerView = (RecyclerView) view.findViewById(R.id.dataRecyclerView);
        Log.i("ADAPTER", "RecyclerView has been initialized.");
    }

    private void setupRecyclerView() {
        mRecyclerView.setHasFixedSize(true);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        Log.i("ADAPTER", "RecyclerView has been setup.");
    }

    public void setAdapter(MyAdapter adapter) {
        mAdapter = adapter;
        mRecyclerView.setAdapter(mAdapter);
        Log.i("ADAPTER", "Adapter has been set." + mAdapter.getItemCount());
    }
}
</code></pre>

<p><strong>MyAdapter.java</strong> (The <code>RecyclerView</code>'s adapter)</p>

<pre><code>public class MyAdapter extends RecyclerView.Adapter&lt;MyAdapter.ViewHolder&gt; {

    protected Context mContext;
    protected List&lt;String&gt; mItems;

    public MyAdapter(Context context, List&lt;String&gt; items) {
        mContext = context;
        mItems = new ArrayList&lt;&gt;(items);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_row, parent, false);
        Log.i("ADAPTER", "Creating row...");

        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.label.setText(mItems.get(position));
    }

    @Override
    public int getItemCount() {
        return mItems.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        TextView label;

        public ViewHolder(View itemView) {
            super(itemView);
            label = (TextView) itemView.findViewById(R.id.label);
        }
    }
}
</code></pre>

<p><strong>item_row.xml:</strong> (the XML layout of the <code>RecyclerView</code>'s elements)</p>

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

    &lt;TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="New Text"
        android:id="@+id/label"
        android:gravity="left|center_vertical"
        android:padding="8dp"
        android:background="#ff0000"/&gt;
&lt;/LinearLayout&gt;
</code></pre>

<p><strong>refreshable_list.xml:</strong> (The XML layout of the <code>RefreshableList</code> custom view)</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:orientation="vertical"&gt;

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

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

<p>All this code belongs to the <strong>rlist</strong> module. In order to test it out, I added a <code>MainActivity</code> to the <strong>app</strong> module where I embed a <code>RefreshableList</code>:</p>

<p><strong>MainActivity.java</strong></p>

<pre><code>public class MainActivity extends AppCompatActivity {

    @Bind(R.id.list)
    RefreshableList mRefreshableList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);

        mRefreshableList.setAdapter(new MyAdapter(
                this, Arrays.asList("Java", "Android", "Python", "Kivy")));
    }
}
</code></pre>

<p><strong>activity_main.xml</strong></p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.zouag.refreshablelist.MainActivity"
    android:background="#00ff00"&gt;

    &lt;com.zouag.rlist.RefreshableList
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#ffff00"/&gt;
&lt;/RelativeLayout&gt;
</code></pre>

<p>After running the application, I can't see any of the <code>RecyclerView</code>'s elements: (even though the <code>RecyclerView</code> is clearly visible, marked with yellow)</p>

<p><a href="https://i.stack.imgur.com/nYF8E.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nYF8E.png" alt="Run"></a></p>

<p>What am I missing here ?</p>