title: Inflate layout having nested RecyclerView that needs to be inflated again
body: <p>I have an initial recyclerview for comments which I am able to retrieve from the Firebase database by inflating a layout. The inflated layout has another recyclerview for replies on comments. Currently I am able to successfully save the replies for the comments as well in the database. My problem is that how can I retrieve replies for the comments within the (Comments inflated layout) recyclerview. The recyclerview for the replies lies inside the first initial inflated layout for the comments..</p>
  
  <p><a href="https://i.stack.imgur.com/yBP0V.png" rel="nofollow noreferrer">This image recyclerview is for the comments</a></p>
  
  <p><a href="https://i.stack.imgur.com/gsrE8.png" rel="nofollow noreferrer">this is the inflated layout for comments with the recyclerview for replies</a></p>
  
  <p><a href="https://i.stack.imgur.com/EuU9w.png" rel="nofollow noreferrer">this is the supposed inflated layout which should be inflated for the replies</a></p>
  
  <p><a href="https://i.stack.imgur.com/q4PL3.png" rel="nofollow noreferrer">Database Structure</a></p>
  
  <p>Below is my code</p>
  
  <pre><code> @Override
  protected void onCreate(Bundle savedInstanceState) {
   firebaseAuth = FirebaseAuth.getInstance();
      currentUserID = firebaseAuth.getCurrentUser().getUid();
      UserBids = FirebaseDatabase.getInstance().getReference().child("All Bids");
      UsersRef = FirebaseDatabase.getInstance().getReference().child("Users");
  
  
      CommentsRecyclerview = findViewById(R.id.Comments_recycler_view);
      CommentsRecyclerview.setHasFixedSize(true);
      CommentsRecyclerview.setNestedScrollingEnabled(false);
      LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
  
      linearLayoutManager.setReverseLayout(true);
      linearLayoutManager.setStackFromEnd(true);
      CommentsRecyclerview.setLayoutManager(linearLayoutManager);
  
  @Override
  protected void onResume() {
      super.onResume();
  
  
      WorkingDataForDisplayingDetails.addValueEventListener(new ValueEventListener() {
          @Override
          public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
              if (dataSnapshot.exists()) {
                  Object userid = dataSnapshot.child("currentUserid").getValue();
                  if (userid != null) {
                      postedUserID = userid.toString();
  
  
                      Query query = UserBids.child("Comments").child(PostKey).child(postedUserID);
                      FirebaseRecyclerOptions&lt;Comments&gt; options = new FirebaseRecyclerOptions.Builder&lt;Comments&gt;()
                              .setQuery(query, Comments.class)
                              .build();
  
                      final FirebaseRecyclerAdapter&lt;Comments, MyViewHolder&gt; adapter
                              = new FirebaseRecyclerAdapter&lt;Comments, MyViewHolder&gt;(options) {
                          @Override
                          protected void onBindViewHolder(@NonNull final MyViewHolder holder, int position, @NonNull final Comments model) {
  
                              UserBids.child(PostKey).child(postedUserID).addValueEventListener(new ValueEventListener() {
                                  @Override
                                  public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                                      if (dataSnapshot.hasChild(model.getCurrentuserid())) {
                                          holder.bidder.setText("Bidder");
                                      }
                                  }
  
                                  @Override
                                  public void onCancelled(@NonNull DatabaseError databaseError) {
  
                                  }
                              });
  
  
                              holder.name.setText(model.getUserName());
                              holder.comment.setText(model.getComment());
                              Picasso.get().load(model.getImage()).placeholder(R.drawable.profile).into(holder.userimg);
  
                              holder.reply.setOnClickListener(new View.OnClickListener() {
                                  @Override
                                  public void onClick(View v) {
                                      postKeyForReply = getRef(holder.getAdapterPosition()).getKey();
  
                                      Log.d(TAG, "onClick: inside reply onclick");
  
                                      holder.replyCommentInput.setVisibility(View.VISIBLE);
                                      holder.replyCommentSendButton.setVisibility(View.VISIBLE);
  
                                      holder.replyCommentInput.setFocusableInTouchMode(true);
                                      holder.replyCommentInput.requestFocus();
  
                                      InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                                      imm.showSoftInput(holder.replyCommentInput, InputMethodManager.SHOW_FORCED);
  
                                  }
                              });
  
  
                              holder.replyCommentSendButton.setOnClickListener(new View.OnClickListener() {
                                  @Override
                                  public void onClick(View v) {
                                      String checkValidReply = holder.replyCommentInput.getText().toString();
                                      if (TextUtils.isEmpty(checkValidReply)) {
                                          Toast.makeText(AllUsersComments.this, "Please write something", Toast.LENGTH_SHORT).show();
                                      } else {
  
                                          final String randomKeyForReply = UserBids.push().getKey();
  
                                          HashMap replyMap = new HashMap();
                                          replyMap.put("currentuserid", currentUserID);
                                          replyMap.put("currentusername", saveFirstNameforReplier);
                                          replyMap.put("reply", checkValidReply);
  
                                          UserBids.child("Reply").child(postKeyForReply)
                                                  .child(currentUserID).child(randomKeyForReply).updateChildren(replyMap)
                                                  .addOnCompleteListener(new OnCompleteListener() {
                                                      @Override
                                                      public void onComplete(@NonNull Task task) {
                                                          if (task.isSuccessful()) {
                                                              Toast.makeText(AllUsersComments.this, "Comment Posted", Toast.LENGTH_SHORT).show();
                                                              holder.replyCommentInput.setText("");
                                                              SharedPreferences sharedPref =
                                                                      PreferenceManager
                                                                              .getDefaultSharedPreferences(AllUsersComments.this);
                                                              SharedPreferences.Editor editor = sharedPref.edit();
  
                                                              editor.putString("postkeyReply", postKeyForReply);
                                                              editor.putString("currentuserid", currentUserID);
                                                              editor.commit();
  
                                                          } else {
                                                              Toast.makeText(AllUsersComments.this, "An Error has occurred", Toast.LENGTH_SHORT).show();
                                                          }
                                                      }
                                                  });
  
                                      }
  
                                  }
                              });
  
  
  
                              String givenDateString = model.getDate();
                              SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy, HH:mm");
                              sdf.setTimeZone(TimeZone.getTimeZone("Asia/Bahrain"));
  
                              long timeInMilliseconds = 0;
                              try {
                                  Date mDate = sdf.parse(givenDateString);
                                  timeInMilliseconds = mDate.getTime();
                              } catch (ParseException e) {
                                  e.printStackTrace();
                              }
                              final CharSequence ch = DateUtils.getRelativeTimeSpanString(timeInMilliseconds, System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS);
                              holder.commentTime.setText(ch);
  
                          }
  
                          @NonNull
                          @Override
                          public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
                              View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.comment_section_individual_row_layout, parent, false);
                              MyViewHolder viewHolder = new MyViewHolder(view);
                              return viewHolder;
                          }
                      };
                      CommentsRecyclerview.setAdapter(adapter);
                      adapter.startListening();
  
  
                  }
              }
  
          }
  
          @Override
          public void onCancelled(@NonNull DatabaseError databaseError) {
  
          }
      });
  
  
  
  }
  
  
  public static class MyViewHolder extends RecyclerView.ViewHolder {
  
      public AppCompatTextView name;
      public AppCompatTextView reply;
      public AppCompatImageView replyCommentSendButton;
      public AppCompatEditText replyCommentInput;
      public AppCompatTextView bidder;
      public AppCompatTextView comment;
      public AppCompatTextView commentTime;
      public CircleImageView userimg;
  
      public MyViewHolder(View itemView) {
          super(itemView);
          name = itemView.findViewById(R.id.CommentersName);
          reply = itemView.findViewById(R.id.ReplyButton);
          bidder = itemView.findViewById(R.id.checkBidder);
          comment = itemView.findViewById(R.id.CommentersComment);
          userimg = itemView.findViewById(R.id.UserImageInComment);
          commentTime = itemView.findViewById(R.id.commentTimeAgo);
          replyCommentSendButton = itemView.findViewById(R.id.replyCommentButton);
          replyCommentInput = itemView.findViewById(R.id.replyCommentInputInReply);
  
  
      }
  }
  </code></pre>