title: How to update an item in Firestore RecyclerView?
body: <p>I am trying to update an item in my <code>RecyclerView</code> with a save button in the toolbar which calls <code>updateQuestion()</code>. </p>
  
  <p>I have this structure in my Firebase:</p>
  
  <p><code>Questions</code></p>
  
  <p>--><code>list_of_documents wUniqueIDs</code> </p>
  
  <p>--->fields in documents:</p>
  
  <p>+<code>question</code></p>
  
  <p>+<code>answer</code></p>
  
  <p>+<code>rating</code></p>
  
  <p>so far i have this under <code>updateQuestion()</code></p>
  
  <pre><code>private void updateQuestion() {
          String questionString = mQuestionTextView.getText().toString();
          Object updatedText = mQuestionEditText.getText().toString();
          String questionPath2 = rootRef.collection("Questions").document().getPath();
  
          FirebaseFirestore rootRef = FirebaseFirestore.getInstance();
  
          CollectionReference collectionReference = rootRef.collection(questionPath2).document().update("question", updatedText); // &lt;--- I GET ERROR HERE
  }
  </code></pre>
  
  <pre><code>error: incompatible types: Task&lt;Void&gt; cannot be converted to CollectionReference
  </code></pre>
  
  <p>I also got an error previously saying that the second parameter for <code>update()</code> needs to be an object however this error has seemed to disappear.</p>
  
  <p>I've been trying to follow tutorials and looking at other posts on stackOverflow but none seem to address this.</p>
  
  <p>Here is what i've tried previously:</p>
  
  <pre><code>//        CollectionReference ref = rootRef.collection("Questions").document().collection("question");
  //        CollectionReference ref = rootRef.collection("Questions").document().collection(questionPath);
  
  //        Toast.makeText(this, "this is the path: " + questionPath, Toast.LENGTH_SHORT).show();
  //        Log.d(TAG, "updateQuestion: " + ref.get(question.getAnswer));
  //        Log.d(TAG, "updateQuestion: " + ref.collection(questionPath).document("question", questionPath).toString())
  //        Log.d(TAG, "updateQuestion: " + ref.document(questionPath)("question").toString());
  //        Log.d(TAG, "updateQuestion: " + ref.document(questionPath).get(question).toString());
  //        ref.collection("question")
  //        db.child("Spacecraft").push().setValue(spacecraft);
  //        rootRef.collection("Questions").document().update("question", updatedText);
  //        rootRef.collection("Questions").document(questionPath).update("question", updatedText);
  
  //        TextView savedText = mQuestionTextView.setText(updatedText);
  
  //        DocumentReference documentReference = rootRef.collection("Questions").document(questionPath).update("question", );
  //        DocumentReference documentReference = rootRef.document(questionPath).update("question", updatedText);
  //        CollectionReference collectionReference = rootRef.collection(questionPath).document().update("question", updatedText);
  </code></pre>
  
  <p>Any and all help is appreciated.</p>
  
  <p>------------------ <strong>Revised Code as of 2019 - 04 - 07 @ 1153pm</strong> ---------</p>
  
  <pre><code>@Override
      public boolean onOptionsItemSelected(MenuItem item) {
          switch (item.getItemId()) {
  
              case R.id.save_question:
                  mShowSaveIcon = false;
                  updateQuestion();
                  break;
  
              case R.id.edit_question:
                  item.setVisible(false);
                  enableEditMode();
                  mShowSaveIcon = true;
                  break;
  
          }
          invalidateOptionsMenu();
          return true;
      }
  
      private void enableEditMode(){
  
          mQuestionEditText = findViewById(R.id.questionEditTextID);
          mPostAnswerButton.setEnabled(false);
          mPostAnswerButton.setBackgroundColor(getResources().getColor(android.R.color.darker_gray));
  
          mCommentButton.setEnabled(false);
          mCommentButton.setBackgroundColor(getResources().getColor(android.R.color.darker_gray));
  
          String questionString = mQuestionTextView.getText().toString();
          mQuestionTextView.setVisibility(View.GONE);
          mQuestionEditText.setVisibility(View.VISIBLE);
          mQuestionEditText.setText(questionString);
      }
  
  
  
      private void updateQuestion(){
          Question question = createQuestionObj();
          updateQuestionToCollection(question);
      }
  
      private Question createQuestionObj(){
          final Question question = new Question();
          return question;
      };
  
  private void updateQuestionToCollection(Question question) {
          String questionString = mQuestionTextView.getText().toString();
          Object updatedText = mQuestionEditText.getText().toString();
  
  
          FirebaseFirestore rootRef = FirebaseFirestore.getInstance();
          String docId = rootRef.collection("Questions").document().getId();
          System.out.println(docId);
          String questionPath = rootRef.collection("Questions").document(docId).collection("question").getPath();
  //        String questionPath2 = rootRef.collection("Questions").document(docId).getPath();
  
          System.out.println(questionPath);
          rootRef.collection(questionPath).document(docId).update("question", updatedText).addOnSuccessListener(new OnSuccessListener&lt;Void&gt;() {
              @Override
              public void onSuccess(Void aVoid) {
                  Log.d(TAG, "onSuccess: it worked");
              }
          }).addOnFailureListener(new OnFailureListener() {
              @Override
              public void onFailure(@NonNull Exception e) {
                  Log.d(TAG, "onFailure: it failed because of: " + e.toString());
              }
          });
  
  finish();
   }
  };
  </code></pre>
  
  <p><strong>DataBase Structure Snippet Below</strong></p>
  
  <p><a href="https://i.stack.imgur.com/E5LrH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/E5LrH.png" alt="enter image description here"></a></p>