title: How to stop RecyclerView Items from Displaying Out of Order
body: <p>I'm using a RecyclerView to display messages from a user and a bot, but after about 10 messages, upon scrolling, the RecyclerView's items display out of order.</p>
  
  <p>I removed <code>setStackFromEnd()</code> and <code>setReverseLayout()</code> from the LinearLayoutManager my code in case that caused any issue, but that didn't solve the problem. I also added the line <code>holder.setIsRecyclable(false);</code>, and although that worked, I didn't want to use that solution since it defeats the purpose of a RecyclerView.</p>
  
  <p>Gets user response, adds the response to the list of messages, generates the reply, and calls calls <code>updateUI()</code>:</p>
  
  <pre><code>public void respond(String input) {
      int position = getMessagePosition();
      Log.d(CHAT_FRAGMENT_TAG, "Received Message: " + input);
      String reply = mBot.reply("user", input);
      Log.d(CHAT_FRAGMENT_TAG, "Bot Reply: " + reply);
      mMessages.add(new Message(reply, Message.BOT_MESSAGE, messagePosition()));
      updateUI(position);
      Log.d(CHAT_FRAGMENT_TAG, "mMessages List: " + mMessages.get(position).getText());
  }
  </code></pre>
  
  <p><code>updateUI()</code>:</p>
  
  <pre><code>public void updateUI(int insertPosition) {
      if (mAdapter == null) {
          mAdapter = new MessageAdapter();
          mRecyclerView.setAdapter(mAdapter);
      } else
          mAdapter.notifyItemInserted(insertPosition);
  }
  </code></pre>
  
  <p><code>onBindViewHolder()</code>:</p>
  
  <pre><code>@Override
      public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
          Message message = mMessages.get(position);
  
          if (getItemViewType(position) == Message.USER_MESSAGE)
              ((UserMessageHolder) holder).bind(message);
          else
              ((BotMessageHolder) holder).bind(message);
      }
  </code></pre>
  
  <p><code>bind()</code>:</p>
  
  <pre><code>public void bind(Message message) {
          mBotTextView.setText(message.getText());
      }
  </code></pre>
  
  <p><code>messagePosition()</code> and <code>getMessagePosition()</code>:</p>
  
  <pre><code>    public static int messagePosition() {
      //A convenience function to get the current position and increment it as well for the next array element.
      int returnValue = mMessagePosition;
      mMessagePosition++;
      return returnValue;
  }
  
  public static int getMessagePosition() {
      return mMessagePosition;
  }
  </code></pre>
  
  <p>There is an <code>onClick()</code> method on an EditText that  takes the user's response and calls the <code>respond()</code> method. The <code>respond()</code> method gets the bot's reply, and it calls the <code>updateUI()</code> method to let the adapter know that the array is larger since new messages were added (one from the user and one from the bot). This process works fine until there are about 10 messages and the user needs to scroll. From that point, the messages reload on the screen incorrectly by repeating themselves or not loading in their correct spot.</p>