title: How to show a different item between two different items in a recyclerView?
body: <p>I am working on a chat app, And there are two types of views, one is for incoming messages and another is for outgoing messages. So I differentiate them by view type as 0 and 1. So it is working awesome but now I want to add another view for the date as a header like <a href="https://images.app.goo.gl/B2ZEK2W9KdEZnTHr8" rel="nofollow noreferrer">this</a>. So for this, I made another view type as 2 but It replaces it with the message view. So, How can I show the 3rd view between the 2 views?</p>
  <p>This is how I create the <code>ViewHolder</code></p>
  <pre><code>override fun onCreateViewHolder(parent: ViewGroup, position: Int): ViewHolder {
          return if (position == 1) {
              val view = LayoutInflater.from(mContext).inflate(R.layout.item_outgoing_message, parent, false)
              ViewHolder(view)
          } else if (position == 0) {
              val view = LayoutInflater.from(mContext).inflate(R.layout.item_incoming_message, parent, false)
              ViewHolder(view)
          } else {
              val view = LayoutInflater.from(mContext).inflate(R.layout.item_show_time_chat, parent, false)
              ViewHolder(view)
          }
      }
  </code></pre>
  <p>This is the way I differentiate the <code>ViewType</code></p>
  <pre><code> override fun getItemViewType(position: Int): Int {
          return if (mChatList[position].getSender() == currentUserID) {
              1
          }
          else if (mChatList[position].getMessageDate() == getTheRecentMessageDate(position)){
              2
          }
          else {
              0
          }
      }
  </code></pre>
  <p>This is to get the difference between dates</p>
  <pre><code>private fun getTheRecentMessageDate(position: Int): String {
          val lastMessagePosition = position - 1
          //return the 1st message if messages chat thread is empty
          val chat = mChatList[if (lastMessagePosition &lt;= 0) 0 else lastMessagePosition]
          //get and return the sender of the last message
          return chat.getMessageDate()
      }
  </code></pre>
  <p>And Finally applying it in <code>BindViewHolder</code></p>
  <pre><code>if (mChatList[position].getMessageDate() == getTheRecentMessageDate(position)){
              holder.showDateTv?.text = getTheRecentMessageDate(position)
          }
  </code></pre>