title: How to sort RecyclerView elements with different types?
body: <p>I have a problem with sorting <code>RecyclerView</code> items with different types. For example i have such <code>RecyclerView.Adapter</code>:</p>
  
  <pre><code>public class StudyRVadapter extends RecyclerView.Adapter&lt;RecyclerView.ViewHolder&gt;{
  
  private List&lt;Item&gt; data;
  
  public RVadapter(List&lt;Item&gt; src){
      data = src;
  }
  
  @Override
  public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
      View view;
      RecyclerView.ViewHolder vh;
  
      switch (viewType){
          case 0:
              view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_0, parent, false);
              vh = new ViewHolderZero(view);
              break;
  
          case 1:
              view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_1, parent, false);
              vh = new ViewHolderOne(view);
              break;
  
          default: vh=null;
      }
      return vh;
  }
  
  @Override
  public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
  
      if (Item0.class.isInstance(data.get(position))){
          Item0 item0 = (Item0)data.get(position);
          ((ViewHolderZero)holder).text.setText(item0.toStringText());
           }
      if (Item1.class.isInstance(data.get(position))){
          Item1 item1 = (Item1)data.get(position);
         ((ViewHolderOne)holder).text.setText(item1.toStringText());
      }      
  }
  
  @Override
  public int getItemViewType(int position) throws IllegalArgumentException {
      Item item = data.get(position);
      if (Item0.class.isInstance(item)) return 0;
      if (Item1.class.isInstance(item)) return 1;
      throw  new IllegalArgumentException("Unknown element");
  }
  
  @Override
  public int getItemCount() {
      return data.size();
  }
  
  public class ViewHolderZero extends RecyclerView.ViewHolder{
  
      TextView text;
  
      public ViewHolderZero(View itemView) {
          super(itemView);
          text = (TextView)itemView.findViewById(R.id.tvItem0);
  
      }
  }
  
  public class ViewHolderOne extends RecyclerView.ViewHolder {
       TextView text2;
  
      public ViewHolderOne(View itemView) {
          super(itemView);
          text = (TextView)itemView.findViewById(R.id.tvItem1);
      }
  }
  </code></pre>
  
  <p>In my main <code>Activity</code> i create <code>LinkedList</code> and add elements with types "Item0" and "Item1":</p>
  
  <pre><code>LinkedList&lt;Item&gt; ll = new LinkedList&lt;&gt;();
  ll.add(0, new Item0("abc"));
  ll.add(1, new Item1("bca"));
  </code></pre>
  
  <p>i tried to use <code>Comparator</code>:</p>
  
  <pre><code>class Comparation implements Comparator&lt;Item&gt; {
  
      public int compare(Item0 lhs, Item1 rhs) {
  
          if (lhs.getText() &lt; rhs.getText()){
              return 1;
          }else return -1;
      }
  }
  </code></pre>
  
  <p>But it doesn't work because of wrong args in <code>compare()</code>.</p>
  
  <p>If i understand correctly, i can use <code>Collections.sort()</code> and <code>Comparator</code> for list, wich consists of same-type elements. But how can i sort different-type elements?</p>