title: Make a delete button for RecyclerView in Kotlin
body: <p>This is my first app in Kotlin, but I don't think I am understanding well the logic. I am trying to make a delete button for every single element in a List with Recycler View:</p>
  <p>my MusicianRecyclerAdapter:</p>
  <pre><code>package com.example.genremusicians
  
  import android.content.Context
  import android.content.Intent
  import android.view.LayoutInflater
  import android.view.View
  import android.view.ViewGroup
  import android.widget.TextView
  import androidx.recyclerview.widget.RecyclerView
  import com.example.genremusicians.Models.MusicianInfo
  import kotlinx.android.synthetic.main.item_musician_list.view.*
  
  class MusicianRecyclerAdapter (private val context: Context, private val musicians:List&lt;MusicianInfo&gt;) : RecyclerView.Adapter&lt;MusicianRecyclerAdapter.ViewHolder&gt;() {
  
      private val  layoutInflater = LayoutInflater.from(context)
      inner class ViewHolder(itemView: View): RecyclerView.ViewHolder(itemView){
          val deleteButton = itemView.deleteButton
          val textGenre = itemView.findViewById&lt;TextView&gt;(R.id.textViewTitle)
          val textMusician = itemView.findViewById&lt;TextView&gt;(R.id.textViewText)
          var musicianPosition = 0
          init {
              itemView.setOnClickListener{
                  val intent = Intent(context,MainActivity::class.java)
                  intent.putExtra(EXTRA_MUSICIAN_POSITION,musicianPosition)
                  context.startActivity(intent)
              }
          }
          init {
              deleteButton.setOnClickListener{
                  val intent = Intent(context,MainActivity::class.java)
                  intent.removeExtra(EXTRA_MUSICIAN_POSITION)
                  context.startActivity(intent)
              }
          }
      }
  
      override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
          val itemView = layoutInflater.inflate(R.layout.item_musician_list,parent, false)
          return ViewHolder(itemView)
      }
  
      override fun getItemCount(): Int {
          return musicians.size
      }
  
      override fun onBindViewHolder(holder: ViewHolder, position: Int) {
          var musician = musicians[position]
          holder.textGenre.text = musician.genre?.title
          holder.textMusician.text = musician.name
          holder.musicianPosition = position
      }
  }
  </code></pre>
  <p>and this is my MainActivity</p>
  <pre><code>package com.example.genremusicians
  
  import androidx.appcompat.app.AppCompatActivity
  import android.os.Bundle
  import android.view.Menu
  import android.view.MenuItem
  import android.widget.ArrayAdapter
  import com.example.genregenres.Models.DataManager
  import com.example.genremusicians.Models.GenreInfo
  import com.example.genremusicians.Models.MusicianInfo
  import kotlinx.android.synthetic.main.activity_main.*
  
  class MainActivity : AppCompatActivity() {
      private var musicianPosition = POSITION_NOT_SET
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_main)
  
          var adapterGenres = ArrayAdapter&lt;GenreInfo&gt;(
              this,
              android.R.layout.simple_spinner_item,
              DataManager.genres.values.toList()
          )
  
          adapterGenres.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line)
          spinnerGenre.adapter = adapterGenres
  
          musicianPosition = savedInstanceState?.getInt(EXTRA_MUSICIAN_POSITION, POSITION_NOT_SET)
              ?: intent.getIntExtra(EXTRA_MUSICIAN_POSITION, POSITION_NOT_SET)
  
  
          if (musicianPosition != POSITION_NOT_SET) {
              displayMusician()
          } else {
              createMusician()
          }
  
      }
  
      private fun createMusician() {
          DataManager.musicians.add(MusicianInfo())
          musicianPosition = DataManager.musicians.lastIndex
      }
  
      override fun onRestart() {
          super.onRestart()
      }
  
      override fun onPause() {
          super.onPause()
          saveMusician()
      }
  
      private fun saveMusician() {
          val musician = DataManager.musicians[musicianPosition]
          musician.name = editTextName.text.toString()
          musician.album = editTextAlbum.text.toString()
          musician.genre = spinnerGenre.selectedItem as GenreInfo
      }
  
      override fun onStop() {
          super.onStop()
      }
  
      override fun onSaveInstanceState(outState: Bundle) {
          super.onSaveInstanceState(outState)
          outState.putInt(EXTRA_MUSICIAN_POSITION, musicianPosition)
      }
  
      private fun displayMusician() {
          val musician = DataManager.musicians[musicianPosition]
          editTextName.setText(musician.name)
          editTextAlbum.setText(musician.album)
          val genrePosition = DataManager.genres.values.indexOf(musician.genre)
          spinnerGenre.setSelection(genrePosition)
      }
  
      override fun onCreateOptionsMenu(menu: Menu?): Boolean {
          menuInflater.inflate(R.menu.menu_main, menu)
          return super.onCreateOptionsMenu(menu)
      }
  
      override fun onOptionsItemSelected(item: MenuItem): Boolean {
          when (item.itemId) {
              R.id.action_settings -&gt; true
              R.id.action_next -&gt; {
                  MoveNext()
              }
              else -&gt; super.onOptionsItemSelected(item)
          }
          return super.onOptionsItemSelected(item)
      }
  
      override fun onPrepareOptionsMenu(menu: Menu?): Boolean {
          if (musicianPosition &gt;= DataManager.musicians.lastIndex) {
              var item = menu?.findItem(R.id.action_next)
              if (item != null) {
                  item.icon = getDrawable(R.drawable.ic_baseline_block_24)
                  item.isEnabled = false
              }
          }
          return super.onPrepareOptionsMenu(menu)
      }
  
      override fun invalidateOptionsMenu() {
          super.invalidateOptionsMenu()
      }
  
      private fun MoveNext() {
          musicianPosition++
          displayMusician()
          invalidateOptionsMenu()
      }
  }
  </code></pre>
  <p>I have my Data from a file I created to start learning, but I don't understand what I am doing wrong to create a delete button, and how I should do it. Thank you all</p>