title: Adding item in new collection when clicking on RecyclerView using FirestoreRecyclerAdapter
body: <p>My requirement is to add the item details in a new collection when I click on the add button inside the <code>RecyclerView</code> item.</p>
  <p>Currently I am retrieving data from Firestore collection into the <code>RecyclerView</code>, now I need to add the data inside the item to the new collect using the same document ID when I click on add button.</p>
  <p>Any one please help me to sort it out.</p>
  <h2>GroceryCat</h2>
  <pre><code>public class GroceryCat extends AppCompatActivity {
  
      private FirebaseFirestore db = FirebaseFirestore.getInstance();
      private GroceryCatAdapter adapter;
  
      @Override
      protected void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.grocerycat);
          setUpRecyclerView();
      }
  
      private void setUpRecyclerView() {
  
          // create the get Intent object
          Intent intent = getIntent();
  
          // receive the value by getStringExtra() method
          // and key must be same which is send by first activity
          String str = intent.getStringExtra(&quot;documentID&quot;);
          Toast.makeText(GroceryCat.this,&quot; ID: &quot; + str, Toast.LENGTH_SHORT).show();
  
          CollectionReference productsRef = db.collection(&quot;Inventory&quot;).document(str).collection(&quot;Productslist&quot;);
  
          Query query = productsRef.orderBy(&quot;name&quot;, Query.Direction.DESCENDING);
  
          FirestoreRecyclerOptions&lt;GroceryCatModel&gt; options = new FirestoreRecyclerOptions.Builder&lt;GroceryCatModel&gt;().setQuery(query, GroceryCatModel.class).build();
  
          adapter = new GroceryCatAdapter(options);
  
          RecyclerView recyclerView = findViewById(R.id.recycler_view);
          recyclerView.setHasFixedSize(true);
          recyclerView.setLayoutManager(new LinearLayoutManager(this));
          recyclerView.setAdapter(adapter);
  
         // Onclick for item in the list
  
          adapter.setOnItemClickListener(new GroceryCatAdapter.OnItemClickListener() {
              @Override
              public void onItemClick(DocumentSnapshot documentSnapshot, int position) {
                  GroceryStoresModel groceryStoresModel = documentSnapshot.toObject(GroceryStoresModel.class);
                  String id = documentSnapshot.getId();
                  String path = documentSnapshot.getReference().getPath();
  
                  //Toast displaying the document id
  
                  Toast.makeText(GroceryCat.this,
                          &quot;Position: &quot; + position + &quot; ID: &quot; + id, Toast.LENGTH_SHORT).show();
  
              }
          });
      }
  
  }
  </code></pre>
  <h2>GroceryCatAdapter</h2>
  <pre><code>public class GroceryCatAdapter extends FirestoreRecyclerAdapter&lt;GroceryCatModel, GroceryCatAdapter.NoteHolder&gt; {
  
      private GroceryCatAdapter.OnItemClickListener listener;
      private FirebaseFirestore db = FirebaseFirestore.getInstance();
  
      GroceryCatAdapter(@NonNull FirestoreRecyclerOptions&lt;GroceryCatModel&gt; options) {
          super(options);
      }
  
      @Override
      protected void onBindViewHolder(@NonNull GroceryCatAdapter.NoteHolder holder, int position, @NonNull GroceryCatModel model) {
          holder.textViewName.setText(model.getName());
          holder.textViewQuantity.setText(model.getQuantity());
          holder.textViewCost.setText(String.valueOf(&quot;Rs&quot;+ model.getCost())  );
      }
  
      @NonNull
      @Override
      public GroceryCatAdapter.NoteHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
          View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.grocerycatrow_item, parent, false);
          return new GroceryCatAdapter.NoteHolder(v);
      }
  
      class NoteHolder extends RecyclerView.ViewHolder {
          TextView textViewName;
          TextView textViewQuantity;
          TextView textViewCost;
          Button btn;
  
          NoteHolder(View itemView) {
              super(itemView);
              textViewName = itemView.findViewById(R.id.text_view_name);
              textViewQuantity = itemView.findViewById(R.id.text_view_quantity);
              textViewCost = itemView.findViewById(R.id.text_view_cost);
              btn = itemView.findViewById(R.id.btn);
  
              itemView.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                      int position = getAdapterPosition();
                      if (position != RecyclerView.NO_POSITION &amp;&amp; listener != null) {
                          listener.onItemClick(getSnapshots().getSnapshot(position), position);
                      }
                  }
              });
          }
      }
  
      public interface OnItemClickListener {
          void onItemClick(DocumentSnapshot documentSnapshot, int position);
      }
  
      public void setOnItemClickListener(GroceryCatAdapter.OnItemClickListener listener) {
          this.listener = listener;
      }
  }
  </code></pre>
  <h2>GroceryCatModel</h2>
  <pre><code>public class GroceryCatModel {
      private String name;
      private String quantity;
      private int cost;
      
      /*Constructors getters and setters*/
  }
  </code></pre>