title: Sorting a Recyclerview
body: <p>Hi guys How would i be able to sort a recyclerview by the data that is within a certain textview which is inside each item inside the recyclerview. I also would love to know how to add a header to each item that is different in the data. ie.</p>
  
  <p>Im sorting trying to sort by a date and I want all the dates of xyz to be grouped under one header and the dates of 123 to be grouped under anther geader. Is this possible thanks.</p>
  
  <p>Ill post my adapter for now if you need other information just comment under this. Cheers.</p>
  
  <p>Here is the code which is stated in the fragment the recyclerview is in.</p>
  
  <pre><code> mAdapter = new RecyclerViewAdapterTransactions(getActivity(), account, amount, incomeExpense, type, date, category, uid, description);
               ((RecyclerViewAdapterTransactions) mAdapter).setMode(Attributes.Mode.Single);
               recyclerView.setHasFixedSize(true);
               recyclerView.setAdapter(mAdapter);
  </code></pre>
  
  <p>RecyclerViewAdapterTransactions adapter:</p>
  
  <pre><code>    public class RecyclerViewAdapterTransactions extends RecyclerSwipeAdapter&lt;RecyclerViewAdapterTransactions.SimpleViewHolder&gt;{
  
     public static class SimpleViewHolder extends RecyclerView.ViewHolder {
  
        SwipeLayout swipeLayout;
        ImageButton buttonDelete;
        ImageButton buttonEdit;
  
        TextView textViewAccount;
        TextView textViewAmount;
        TextView textViewIncomeExpense;
        TextView textViewDate;
        TextView textViewUID;
        TextView textViewCategory;
        TextView textViewDescription;
        TextView textViewType;
  
        public SimpleViewHolder(View itemView) {
           super(itemView);
           swipeLayout = (SwipeLayout) itemView.findViewById(R.id.swipeLayoutTransactions);
           buttonDelete = (ImageButton) itemView.findViewById(R.id.imageButtonTransactionDelete);
           buttonEdit = (ImageButton) itemView.findViewById(R.id.imageButtonTransactionEdit);
  
           textViewAmount = (TextView) itemView.findViewById(R.id.textViewAmount);
           textViewAccount = (TextView) itemView.findViewById(R.id.textViewAccount);
           textViewIncomeExpense = (TextView) itemView.findViewById(R.id.textViewIncomeExpense);
           textViewType = (TextView) itemView.findViewById(textViewTransactionType);
           textViewDate = (TextView) itemView.findViewById(R.id.textViewDateOfTransaction);
           textViewCategory = (TextView) itemView.findViewById(R.id.textViewCategory);
           textViewUID = (TextView) itemView.findViewById(R.id.id);
           textViewDescription = (TextView) itemView.findViewById(R.id.textViewDescription);
  
  
        }
     }
  
     private Context mContext;
     private ArrayList&lt;String&gt; account;
     private ArrayList&lt;String&gt; amount;
     private ArrayList&lt;String&gt; incomeExpense;
     private ArrayList&lt;String&gt; type;
     private ArrayList&lt;String&gt; date;
     private ArrayList&lt;String&gt; category;
     private ArrayList&lt;String&gt; uid;
     private ArrayList&lt;String&gt; description;
  
  
     public RecyclerViewAdapterTransactions(Context context, ArrayList&lt;String&gt; account, ArrayList&lt;String&gt; amount, ArrayList&lt;String&gt; incomeExpense, ArrayList&lt;String&gt; type, ArrayList&lt;String&gt; date, ArrayList&lt;String&gt; category, ArrayList&lt;String&gt; uid, ArrayList&lt;String&gt; description) {
        this.mContext = context;
        this.account = account;
        this.amount = amount;
        this.incomeExpense = incomeExpense;
        this.type = type;
        this.date = date;
        this.category = category;
        this.uid = uid;
        this.description = description;
     }
  
  
  
     @Override
     public SimpleViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.listview_transactions, parent, false);
        return new SimpleViewHolder(view);
     }
  
  
     @Override
     public void onBindViewHolder(final SimpleViewHolder viewHolder, final int position) {
  
        String itemAccount = account.get(position);
        String itemAmount = amount.get(position);
        String itemIncomeExpense = incomeExpense.get(position);
        String itemType = type.get(position);
        String itemDate = date.get(position);
        String itemCategory = category.get(position);
        String itemDescription = description.get(position);
        final String itemID = uid.get(position);
  
        viewHolder.swipeLayout.setShowMode(SwipeLayout.ShowMode.LayDown);
  
        viewHolder.buttonDelete.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View view) {
              mItemManger.removeShownLayouts(viewHolder.swipeLayout);
              account.remove(position);
              amount.remove(position);
              incomeExpense.remove(position);
              type.remove(position);
              date.remove(position);
              category.remove(position);
              uid.remove(position);
              description.remove(position);
              notifyItemRemoved(position);
              notifyItemRangeChanged(position, account.size());
              mItemManger.closeAllItems();
  
              TransactionsDatabase transactionsDatabase = new TransactionsDatabase(mContext);
              transactionsDatabase.open();
              transactionsDatabase.deleteEntry(itemID);
              transactionsDatabase.close();
  
           }
        });
  
        viewHolder.buttonEdit.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View view) {
  
              Intent intent = new Intent();
              intent.setClass(mContext, EditTransaction.class);
  
              intent.putExtra("account", account.get(position));//
              intent.putExtra("amount", amount.get(position));//
              intent.putExtra("incomeExpense", incomeExpense.get(position));//
              intent.putExtra("type", type.get(position));//
              intent.putExtra("date", date.get(position));//
              intent.putExtra("category", category.get(position));//
              intent.putExtra("uid", uid.get(position));
              intent.putExtra("description", description.get(position));//
              mContext.startActivity(intent);
  
  
           }
        });
  
  
        Typeface robotoTypeFace = Typeface.createFromAsset(mContext.getAssets(), "fonts/Roboto-Thin.ttf");
        viewHolder.textViewAccount.setText(itemAccount);
        viewHolder.textViewAmount.setText(itemAmount);
        viewHolder.textViewIncomeExpense.setText(itemIncomeExpense);
        viewHolder.textViewType.setText(itemType);
        viewHolder.textViewDate.setText(itemDate);
        viewHolder.textViewCategory.setText(itemCategory);
        viewHolder.textViewUID.setText(itemID);
        viewHolder.textViewDescription.setText(itemDescription);
  
        viewHolder.textViewAccount.setTypeface(robotoTypeFace);
        viewHolder.textViewAmount.setTypeface(robotoTypeFace);
        viewHolder.textViewIncomeExpense.setTypeface(robotoTypeFace);
        viewHolder.textViewType.setTypeface(robotoTypeFace);
        viewHolder.textViewDate.setTypeface(robotoTypeFace);
        viewHolder.textViewCategory.setTypeface(robotoTypeFace);
        viewHolder.textViewUID.setTypeface(robotoTypeFace);
        viewHolder.textViewDescription.setTypeface(robotoTypeFace);
  
        mItemManger.bindView(viewHolder.itemView, position);
     }
  
     @Override
     public int getItemCount() {
        return uid.size();
     }
  
     @Override
     public int getSwipeLayoutResourceId(int position) {
        return R.id.swipeLayoutTransactions;
     }
  
  }
  </code></pre>