title: change background of all other elements in recyclerview
body: <p>When a user clicks a <code>cardView</code> in the <code>recyclerView</code> its background changes color to show its selected. What I'm struggling with is that when I select another card I want the previously selected one to go back to "unselected" form. </p>
  
  <p>How can I get the previously selected <code>cardview</code> to revert back to normal?</p>
  
  <p>This is what I have so far</p>
  
  <pre><code>private fun updateRecyclerViewTest(items: List&lt;Item&gt;) {
      val list = ArrayList&lt;Item&gt;()
      fun init() {
          recycler_view_test.apply {
              layoutManager = LinearLayoutManager(this@EditModActivity, LinearLayoutManager.HORIZONTAL, false)
              adapter = GroupAdapter&lt;ViewHolder&gt;().apply {
                  testSection = Section(items)
                  add(testSection)
                  setOnItemClickListener(onItemClick)
              }
          }
          shouldInitRecyclerView = false
      }
      if (shouldInitRecyclerView)
          init()
      else
      {
          testSection.update(items)
          testSection.setHeader(items[1])
      }
  }
  
  private val onItemClick = OnItemClickListener { item, view -&gt;
      if (item is TestItem) {
          view.backgroundColorResource = R.color.colorAccent1
          txtview1.text = item.test.Desc
          txtview2.text = item.test.module
      }
  }
  </code></pre>
  
  <p>Screenshot:</p>
  
  <p><a href="https://i.stack.imgur.com/eU0dt.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eU0dt.jpg" alt="enter image description here"></a></p>
  
  <p>adapterclass</p>
  
  <pre><code>import android.content.Context
  import com.version.crt.markbuddy.R
  import com.version.crt.markbuddy.model.Test
  import com.xwray.groupie.kotlinandroidextensions.Item
  import com.xwray.groupie.kotlinandroidextensions.ViewHolder
  import kotlinx.android.synthetic.main.item_tape.*
  
  class TestItem(val test: Test,
             val testId: String,
             private val context: Context)
  : Item() {
  override fun bind(viewHolder: ViewHolder, position: Int) {
      viewHolder.textView_title.text = test.Desc
      viewHolder.textView_date.text = "Date: 2018/09/02"
      viewHolder.textView_time.text = "Time: 09:00"
      viewHolder.textView_weighting.text = "Weighting: 50%"
      viewHolder.textView_total.text = "Total: 100"
      viewHolder.textView_achieved.text = "Achieved: 50"
      viewHolder.textView_contribution.text = "End weight: 25%"
  }
  override fun getLayout() = R.layout.item_tape1
  </code></pre>
  
  <p>}</p>
  
  <p>Firebase call method</p>
  
  <pre><code>fun addModInfoListener(type: String,module: String,context: Context, onListen: (List&lt;Item&gt;) -&gt; Unit): ListenerRegistration {
      val items = mutableListOf&lt;Item&gt;()
      return firestoreInstance.collection("test").whereEqualTo("module", module).orderBy("Desc")
              .addSnapshotListener { querySnapshot, firebaseFirestoreException -&gt;
                  if (firebaseFirestoreException != null) {
                      Log.e("FIRESTORE", "Module listener error.", firebaseFirestoreException)
                      return@addSnapshotListener
                  }
                  querySnapshot!!.documents.forEach {
                      items.add(TestItem(it.toObject(Test::class.java)!!, it.id, context))
                  }
                  onListen(items)
              }
  }
  </code></pre>
  
  <p>Thank you</p>