title: OnClick in one RecyclerView item affects other items
body: <blockquote>
  <p><em>Edit #1:</em> Through debugging I've discovered that the bug 'disappears'. Basically I set a breakpoint and slowly go through steps of checking each <code>multiChoiceItem</code> and the heights of the other <code>RecyclerView</code> child items do not change. Does this mean it is a drawing/timing related issue?</p>
  <p><em>Edit #2:</em> Also, a new find, if I change the height of <code>Child: 6</code> it changes for <code>Child: 3</code> and <code>Child: 0</code></p>
  </blockquote>
  <p>I apologize for the long question. I've checked other answers regarding the same problem and none of them apply. I've tried solving this myself and just couldn't so I would love some help. If there is anything I can do to make this easier to read, please let me know and I'll get right on it!</p>
  <p>With the way my code is written, this technically should be impossible to happen but yet here it is.</p>
  <hr />
  <p><strong>The Problem:</strong> I have an <code>onClickListener()</code> for a <code>TextView</code> within a <code>RecyclerView</code> item. The <code>onClickListener()</code> calls a <code>multiChoiceItem AlertDialog</code> in the container class of the <code>RecyclerAdapter</code> which then calls <code>notifyDataSet()</code>, after completed, with an <code>addOnLayoutChangeListener()</code> at the end which measures the height after the new <code>RecyclerView</code> is drawn.</p>
  <p>Notifying that the data set ended then causes the <code>TextView</code> within the <code>RecyclerView</code> item to change to show the text of each <em>Checked</em> item. Then this height is measured in the <code>addOnLayoutChangeListener()</code> and sent to a <code>ViewModel</code> which measures the height of the same position item of three fragments and sets the items height to the max height so they all look the same height.</p>
  <p><strong>The Confusing Part:</strong> This problem only occurs for one of the three fragments AND the other effected item heights do not match the other two fragments. Which tells me that this is localized to one fragment (which has its own class)</p>
  <hr />
  <p><strong>The Code:</strong>
  The code is long so I reduced it to what I think was important</p>
  <p><strong>The ViewHolder</strong></p>
  <pre><code>class TextViewViewHolder extends RecyclerView.ViewHolder {
  
      TextView vhTVTextView;
      TextView vhTVMainTextView;
      CardView vhTVCardView;
      TextViewClickedListener vhTextViewClickedListener;
  
      // Gets current position from 'onBindViewHolder'
      int vhPosition = 0;
  
      public TextViewViewHolder(View itemView, TextViewClickedListener textViewClickedListener) {
          super(itemView);
  
          this.vhTextViewClickedListener = textViewClickedListener;
  
          this.vhTVCardView = itemView.findViewById(R.id.thoughtCard);
          this.vhTVTextView = itemView.findViewById(R.id.thoughtNumber);
          this.vhTVMainTextView = itemView.findViewById(R.id.textEntry);
  
          /*
              When the main TextView is clicked, it calls a function in the container
              'FragTextView' which pops up an AlertDialog. It was chosen to do it in the
              container instead of here because the Adapter is so adapt the lists data to the view
              and the container is what dictates what the lists data actually is.
           */
          vhTVMainTextView.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  if(vhTextViewClickedListener != null) {
                      vhTextViewClickedListener.onTextViewClicked(vhPosition);
                  }
              }
          });
      }
  }
  </code></pre>
  <p><strong>onBindViewHolder</strong></p>
  <pre><code>@Override
  public int getItemViewType(int position) {
      /*
          If mThoughtEntries is not null, then that means we can find the ViewType we are working
          with inside of it. Otherwise, we are mDistortions and we must be working on TYPE_TEXTVIEW
       */
      if(mThoughtEntries != null) return mThoughtEntries.get(position).getViewType();
      else return Constants.TYPE_TEXTVIEW;
  }
  
  @Override
  public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
  
      int adapterPosition = holder.getAdapterPosition();
      switch (holder.getItemViewType()) {
          case Constants.TYPE_EDITTEXT:
              EditTextViewHolder editTextViewHolder = (EditTextViewHolder)holder;
              // update MyCustomEditTextListener every time we bind a new item
              // so that it knows what item in mDataset to update
              editTextViewHolder.mMyCustomEditTextListener.setTWPosition(holder.getAdapterPosition());
  
              //Displaying list item to its correct position
              editTextViewHolder.vhETTextView.setText(String.valueOf(adapterPosition + 1));
              editTextViewHolder.vhETEditText.setText(mThoughtEntries.get(adapterPosition).getThought());
              break;
  
          case Constants.TYPE_TEXTVIEW:
              TextViewViewHolder textViewViewHolder = (TextViewViewHolder)holder;
  
              // Send current position to viewHolder so when the text listener is called, it knows
              // exactly which position of the Distortions list to change
              textViewViewHolder.vhPosition = adapterPosition;
  
              //Displaying list item to its correct position
              textViewViewHolder.vhTVTextView.setText(String.valueOf(adapterPosition + 1));
              textViewViewHolder.vhTVMainTextView.setText(distortionsToString(mDistortions.get(adapterPosition)));
  
              break;
      }
  }
  </code></pre>
  <p><strong>AlertDialog in Parent</strong></p>
  <pre><code>@Override
  public void onTextViewClicked(int position) {
      //pass the 'context' here
      AlertDialog.Builder alertDialog = new AlertDialog.Builder(getContext());
      final int recyclerPosition = position;
  
      /*
          Turning the distortions into a list of strings and an array of what should, or should
          not, be checked.
       */
      final String[] distortionStrings = distortionNameToStringArray(mDistortions.get(position));
      final boolean[] checkedDistortions = distortionCheckToBooleanArray(mDistortions.get(position));
  
      alertDialog.setMultiChoiceItems(distortionStrings, checkedDistortions,
              new DialogInterface.OnMultiChoiceClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                      if (isChecked) {
                          // If the user checked the item, add it to the selected items
                          mDistortions.get(recyclerPosition).get(which).setChecked(true);
                      } else {
                          // Else, if the item is already in the array, remove it
                          mDistortions.get(recyclerPosition).get(which).setChecked(false);
                      }
                      /*
                          Because the RecyclerView takes a while to draw, if we call the below function
                          as we normally we would, it would appear to have no effect because it would
                          be automatically overwritten when the RecyclerView is drawn. So we call this
                          onLayout change listener to wait til the view is drawn and then we call
                          the function
                       */
                      mRecyclerView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
                          @Override
                          public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
                              mRecyclerView.removeOnLayoutChangeListener(this);
                              // Send new height to the ViewModel
                              if(mLayoutManager.findViewByPosition(recyclerPosition) != null) {
                                  // Get view of item measuring
                                  View recyclerChild = mLayoutManager.findViewByPosition(recyclerPosition);
                                  // Get LinearLayout from view
                                  LinearLayout linearLayout = recyclerChild.findViewById(R.id.horizontalLayout);
                                  // This is called to find out how big a view should be. The constraints are to check
                                  // measurement when it is set to 'wrap_content'.
                                  linearLayout.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
                                  // Get height of the specified view
                                  int height = linearLayout.getMeasuredHeight();
                                  // Send to child abstracted class which then calls function from 'SharedEntryFragments'
                                  setViewModelHeight(height, recyclerPosition);
                              }
                          }
                      });
                      mAdapter.notifyDataSetChanged();
                  }
              });
  
      alertDialog.setPositiveButton(&quot;Okay&quot;, new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
              // DO SOMETHING HERE
              dialog.cancel();
          }
      });
  
      AlertDialog dialog = alertDialog.create();
      dialog.show();
  }
  </code></pre>
  <p><strong>The function that makes all the fragment item heights equal</strong></p>
  <blockquote>
  <p>I know this part of the code doesn't affect it because where the views that heights are changed are skipped by <code>if(positionalHeight.get(i) != 0) {}</code> So technically...they should never change!</p>
  </blockquote>
  <pre><code>    /*
          This is the listener that will set all the RecyclerViews childrens heights. It
          listens to getTallestLiveHeight() inside of 'SharedEntryFragments.java' and when
          a change occurs, this is called
       */
      if(getActivity() != null) {
          // The container holds the ViewModel so this must make sure getActivity() is not null
          mViewModel = ViewModelProviders.of(getActivity()).get(SharedEntryFragments.class);
          /*
              Creates the observer which updates the UI. The observer takes the
              PositionalHeight class as an input. This class keeps track of which index
              of the RecyclerView to change and what height it will be changed to.
           */
          final Observer&lt;List&lt;Integer&gt;&gt; maxHeight = new Observer&lt;List&lt;Integer&gt;&gt;() {
              @Override
              public void onChanged(@Nullable final List&lt;Integer&gt; positionalHeight) {
                  if (positionalHeight != null) {
                      // Get the index that we are going to change and its height
                      //int position = positionalHeight.getPosition();
                      //int height = positionalHeight.getHeight();
  
                      /*
                          We're going to run through each child of mRecyclerView and change
                          its height accordingly
                       */
                      int listSize = positionalHeight.size();
                      for(int i = 0; i &lt; listSize; i++) {
                          // If height reads zero then skip because it will make our view disappear
                          if(positionalHeight.get(i) != 0) {
                              // This is the child item that we will be changing
                              View recyclerChild = mLayoutManager.findViewByPosition(i);
  
                              // Ensure that the child exists before continuing
                              if (recyclerChild != null) {
                                  // We will be changing the CardView's height
                                  // TODO might have to add a check to detect which viewholder
                                  CardView cardView = recyclerChild.findViewById(R.id.thoughtCard);
                                  // Get the LayoutParams first to ensure everything stays the same
                                  ViewGroup.LayoutParams lparams = cardView.getLayoutParams();
                                  // Get and set height
                                  lparams.height = positionalHeight.get(i);
                                  cardView.setLayoutParams(lparams);
                              }
                          }
                      }
                  }
              }
          };
          mViewModel.getTallestLiveHeight().observe(this, maxHeight);
      }
  }
  </code></pre>