Reuse a inflated view, without inflating more than once
<p>i want to reuse an inflated view just the same way a listView adapter does with convertView. Ive been lurking on the source code of adapters with no luck.</p>

<p>I need to add dinamically views depending on data to a recyclerItemView, now im inflating as much times as i need the view but having in mind its inside a recyclerView, this operation could become absurdly costly depending on the amount of data and scrolling behaviour of the user.</p>

<p>Other solution to my problem would be to create a listview inside the recyclerItem, so the listview wouldnt be scrollable, expands to maximum height depending on data added dynamically(making the listview container to expand to show all its data) and make the recyclerItem expand depending on its height.</p>

<p><strong>ACTIVITY</strong></p>

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

    RecyclerView recyclerView;
    CustomAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main1);
        recyclerView = (RecyclerView) findViewById(R.id.recycler);
        setUpRecycler();
    }

    private void setUpRecycler(){
        Sample sample1 = new Sample("List of Items1");
        Sample sample2 = new Sample("List of Items2");
        Sample sample3 = new Sample("List of Items3");
        List&lt;Sample&gt; sampleList = new ArrayList&lt;&gt;();
        sampleList.add(sample1);
        sampleList.add(sample2);
        sampleList.add(sample3);

        adapter = new CustomAdapter(this,sampleList);
        recyclerView.setAdapter(adapter);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
    }
}

&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:padding="30dp"&gt;

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

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

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

<p><strong>MODEL</strong></p>

<pre><code>public class Sample {

    String name;

    public Sample(){}

    public Sample(String name) {
         this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
</code></pre>

<p><strong>XML ITEMS</strong></p>

<pre><code>**item_list**

&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="40dp"&gt;

&lt;TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/&gt;

&lt;/LinearLayout&gt;

**item_smaple**

&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;TextView
    android:id="@+id/name"
    android:layout_width="120dp"
    android:layout_height="40dp"
    android:layout_margin="10dp"
    android:text="List of Items"
    android:textSize="20sp"/&gt;

&lt;LinearLayout
    android:id="@+id/linearLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="30dp"
    android:orientation="vertical"/&gt;

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

<p><strong>ADAPTER</strong></p>

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

private List&lt;Sample&gt; mySamples;
private Context mContext;

public CustomAdapter(Context context, List&lt;Sample&gt; mySamples) {
    this.mContext = context;
    this.mySamples = mySamples;
}

private Context getContext() {
    return mContext;
}

public static class ViewHolder extends RecyclerView.ViewHolder {

    public TextView name;
    public LinearLayout linearLayout;

    public ViewHolder(View itemView) {
        super(itemView);
        name = (TextView) itemView.findViewById(R.id.name);
        linearLayout = (LinearLayout) itemView.findViewById(R.id.linearLayout);
    }
}

@Override
public CustomAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    Context context = parent.getContext();
    LayoutInflater inflater = LayoutInflater.from(context);
    View contactView = inflater.inflate(R.layout.item_sample, parent, false);
    ViewHolder viewHolder = new ViewHolder(contactView);
    return viewHolder;
}

@Override
public void onBindViewHolder(CustomAdapter.ViewHolder holder, int position) {
    Sample sample = mySamples.get(position);

    holder.name.setText(sample.getName());

    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v = inflater.inflate(R.layout.item_list, null, false);
    for (int i = 0; i &lt; 20; i++){
        TextView textView = (TextView) v.findViewById(R.id.textView);
        textView.setText("hello"+i);
        holder.linearLayout.addView(v);
    }
}

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

<p>Right now i´m inflating inside the loop. How could i modify view parameters to make it reusable to the framework?</p>

<p>My app crashes on the addView()
          -->java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.</p>