title: How do I convert my ListView adapter into RecyclerView adapter?
body: <p>I am currently using a listview instead of a <code>RecyclerView</code> for my data. I was wondering if there's an easy way to convert a <code>ListView</code> adapter to a <code>RecyclerView</code> adapter and hence listview to <code>RecyclerView</code>.</p>
  
  <p>Here's my code so far for the <code>ListView</code> adapter:</p>
  
  <pre><code>public class MyVisitorAdapter extends ArrayAdapter&lt;VisitorItem&gt; implements Filterable {
  
      public ArrayList&lt;VisitorItem&gt; original;
      public ArrayList&lt;VisitorItem&gt; fitems;
      private Filter filter;
      private Context context;
  
      //This whole class needs to be refactored to support binding with viewholders or add recyclerview. This was a trial run to check out
      //how listview pans out, but forgot to remove and update it later
      public MyVisitorAdapter(Context context, ArrayList&lt;VisitorItem&gt; items) {
          super(context, 0, items);
          this.original = new ArrayList&lt;&gt;();
          this.original.addAll(items);
          this.fitems = new ArrayList&lt;&gt;();
          this.fitems.addAll(items);
          this.context = context;
      }
  
      @Override
      public void add(VisitorItem item) {
          this.fitems.add(item);
          this.original.add(item);
          notifyDataSetChanged();
      }
  
      @Override
      public void remove(VisitorItem item) {
          this.fitems.remove(item);
          this.original.remove(item);
          notifyDataSetChanged();
      }
  
      @Override
      public int getCount() {
          return fitems.size();
      }
  
      @Override
      public VisitorItem getItem(int position) {
          return fitems.get(position);
      }
  
      @Override
      public long getItemId(int position) {
          return position;
      }
  
      @Override
      public View getView(final int position, View convertView, ViewGroup parent) {
          LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          View v = vi.inflate(R.layout.item_guest, null);
          VisitorItem item = fitems.get(position);
          if (item != null) {
              TextView firstName = v.findViewById(R.id.firstName);
              firstName.setText(item.firstName);
              TextView lastName = v.findViewById(R.id.lastName);
              lastName.setText(item.lastName);
              TextView email = v.findViewById(R.id.email);
              email.setText(item.email);
              TextView phoneNumber = v.findViewById(R.id.phoneNumber);
              phoneNumber.setText(item.phoneNumber);
              View dividerView = v.findViewById(R.id.item_divider);
              if (getContext() instanceof SubmitGuestsActivity) {
                  dividerView.setVisibility(View.GONE);
              }
  
              if (this.getContext() instanceof MyVisitorActivity) {
                  TextView clearButton = v.findViewById(R.id.item_delete_guest);
                  clearButton.setVisibility(View.VISIBLE);
                  clearButton.setOnClickListener(v1 -&gt; new AlertDialog.Builder(getContext(), R.style.myDialogTheme)
                          .setCancelable(true)
                          .setTitle("Confirm delete")
                          .setMessage("Are you sure?")
                          .setPositiveButton("Yes", (dialog, which) -&gt; {
                              VisitorItem itemToBeDeleted = getItem(position);
                              VisitorItem.delete(VisitorItem.class, itemToBeDeleted.getId());
                              remove(itemToBeDeleted);
                              fitems.remove(itemToBeDeleted);
                              Toast.makeText(getContext(), "Deleted", Toast.LENGTH_SHORT).show();
                          })
                          .setNegativeButton("No", (dialog, which) -&gt; dialog.dismiss())
                          .create().show());
              }
  
          }
          return v;
      }
  
      @Override
      public Filter getFilter() {
          if (filter == null) {
              filter = new ItemsFilter();
          }
          return filter;
      }
  
      private class ItemsFilter extends Filter {
          @Override
          protected FilterResults performFiltering(CharSequence constraint) {
              FilterResults results = new FilterResults();
              String prefix = constraint.toString().toLowerCase();
  
              if (prefix.length() == 0) {
                  ArrayList&lt;VisitorItem&gt; list = new ArrayList&lt;&gt;(original);
                  results.values = list;
                  results.count = list.size();
              } else {
                  final ArrayList&lt;VisitorItem&gt; list = new ArrayList&lt;&gt;(original);
                  final ArrayList&lt;VisitorItem&gt; nlist = new ArrayList&lt;&gt;();
                  int count = list.size();
  
                  for (int i = 0; i &lt; count; i++) {
                      final VisitorItem item = list.get(i);
                      final String firstName = item.firstName.toLowerCase();
                      final String lastName = item.lastName.toLowerCase();
                      final String email = item.email.toLowerCase();
  
                      if (firstName.contains(prefix) &amp;&amp; lastName.contains(prefix) &amp;&amp; email.contains(prefix)) {
                          nlist.add(item);
                      }
  
                  }
                  results.values = nlist;
                  results.count = nlist.size();
              }
  
              return results;
          }
  
          @SuppressWarnings("unchecked")
          @Override
          protected void publishResults(CharSequence constraint, FilterResults results) {
              fitems = (ArrayList&lt;VisitorItem&gt;) results.values;
              MyVisitorAdapter.this.notifyDataSetChanged();
          }
      }
  }
  </code></pre>
  
  <p>In my activity I am calling:</p>
  
  <pre><code>listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
      @Override
      public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
          Intent i = new Intent(MyVisitorActivity.this, AddVisitorActivity.class);
          i.putExtra("firstName", mRegisterAdapter.getItem(position).firstName);
          i.putExtra("lastName", mRegisterAdapter.getItem(position).lastName);
          i.putExtra("email", mRegisterAdapter.getItem(position).email);
          i.putExtra("phoneNumber", mRegisterAdapter.getItem(position).phoneNumber);
          i.putExtra("position", position);
          startActivityForResult(i, 202);
      }
  });
  </code></pre>
  
  <p>Any ideas on how to go about this? </p>
  
  <p>I am currently using my listview and updating items as I go, I would like to convert everything to <code>RecyclerView</code> for better efficiency. </p>
  
  <p>Thanks in advance!</p>