Binding in ViewHolder : <p>This will be theoretical question.</p>

<p>As everyone we use RecyclerView in many parts of the app. Sometimes RecyclerView contains different items, not only image for example, but ads, hints etc. And that's why we can use getViewType() method in Adapter. </p>

<p>But problem occurs when we have many viewTypes and binding this in Adapter is not elegant. So here is the question, <strong>is it nice and good pattern to bind data in ViewHolder?</strong></p>

<p>Let's say we have list of apps.</p>

<p>Every app has name for simplicity. Our ViewHolder looks like this:</p>

<pre><code>class AppViewHolder extends RecyclerView.ViewHolder {

     public TextView nameText;

     AppViewHolder(View itemView) {
          super(itemView)
          nameText = (TextView) itemView.findViewById(R.id.text_name);
     }
}
</code></pre>

<p>Now we could add bind method:</p>

<pre><code>public void bind(App app) {
     nameText.setText(app.getName());
}
</code></pre>

<p>Is it good pattern?</p>

<p>Another solution would be using ViewModel. Because we have different items in RecyclerView, our Adapter could contain list of class which is base class for every ViewModel.</p>

<p>So basic class is:</p>

<pre><code>class RecyclerViewItem {}
</code></pre>

<p>Now class which is ViewModel for App.</p>

<pre><code>class AppRecyclerViewItem extends RecyclerViewItem {

     App app;

     ...
}
</code></pre>

<p>and our Adapter just has list of RecyclerViewItems:</p>

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

    List&lt;RecyclerViewItem&gt; items;

    ...
}
</code></pre>

<p>So with this approach (I mean using ViewModel) is it better to add bind method in ViewHolder, or in ViewModel?</p>
