Recycler View supporting multiple pojo classes
<p>I have a requirement where i have a single recycler view which should be supported by multiple model classes.
My recycler view will inflate multiple different layouts . So to inflate layout i have defined my onCreateViewholder like below : </p>

<pre><code>     @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        RecyclerView.ViewHolder viewHolder = null;
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());

        switch (viewType) {
            case 1:
                View v1 = inflater.inflate(R.layout.searchresultsrow1, parent, false);
                viewHolder = new AppViewHolder(v1);
                break;
            case 2:
                View v2 = inflater.inflate(R.layout.searchresultsrow2, parent, false);
                viewHolder = new AppViewHolder(v2);
                break;
         return viewHolder
}
</code></pre>

<p>On bindview method i use instance of to determine holder type : `</p>

<pre><code>@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        if(holder instanceof AppViewHolder){
            AppViewHolder vh1 = (AppViewHolder) holder;
vh1.appName.setText(Html.fromHtml(**appList**.get(position).getmAppName());
}
} else if (holder instanceof ContactViewHolder){
ContactViewHolder vh3 = (ContactViewHolder) holder; vh3.contactName.setText(Html.fromHtml(**contactList**.get(position).getContactName()));}
}`
</code></pre>

<p>Now i am clueless what to send on itemCount : </p>

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

<p>Since my <strong>applist</strong> object type is different and <strong>contact</strong> list object type is different. <strong>I have tried with switch case in getItemCount but then it only returns the count of single list and displays results only for the particular list whereas i want results combined of both the list</strong>. 
If i send the addition of both the list , then i will encounter <strong>arrayindexoutofbounds</strong> exception. 
What approach can be used in this case ?</p>