title: RecyclerView: viewHolder.adapterPosition returns wrong value
body: <p>I have a RecyclerView to display a list of items user has created. I store names and IDs of items in arrayList using sharedPreferences. I want user to be able to delete items by swiping them, but viewHolder.adapterPosition returns wrong values, as well as viewHolder.layoutPosition, and I don`t know what to do with it, although I have another RecyclerView and there it works perfectly fine.</p>
  <pre><code>abstract class SwipeSchedule(context: Context) : ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT) {
  
      private val deleteColor = ContextCompat.getColor(context, R.color.delete_color)
      private val deleteIcon = R.drawable.ic_delete_24
  
      override fun getMovementFlags(
          recyclerView: RecyclerView,
          viewHolder: RecyclerView.ViewHolder
      ): Int {
          // Check here whatever you want, return 0 if you want disable swipe.
          if (viewHolder.adapterPosition == -1) return 0
  
          return super.getMovementFlags(recyclerView, viewHolder)
      }
  
      override fun onMove(
          recyclerView: RecyclerView,
          viewHolder: RecyclerView.ViewHolder,
          target: RecyclerView.ViewHolder
      ): Boolean {
          return false
      }
  
      override fun onChildDraw(
          c: Canvas,
          recyclerView: RecyclerView,
          viewHolder: RecyclerView.ViewHolder,
          dX: Float,
          dY: Float,
          actionState: Int,
          isCurrentlyActive: Boolean
      ) {
          RecyclerViewSwipeDecorator.Builder(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive)
              .addSwipeLeftBackgroundColor(deleteColor)
              .addSwipeLeftActionIcon(deleteIcon)
              .create()
              .decorate()
          super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive)
      }
  
  }
  </code></pre>
  <p>In MainActivity:</p>
  <pre><code>        val swipeSchedule = object : SwipeSchedule(this
          ) {
              @SuppressLint(&quot;UseCompatLoadingForDrawables&quot;)
              override fun onSwiped(viewHolder: RecyclerView.ViewHolder, direction: Int) {
                  runBlocking {
                      //deleteAnim(viewHolder.adapterPosition)
                      adapter.notifyDataSetChanged()
                      Handler().postDelayed({
                          toast(viewHolder.layoutPosition.toString())
                          //schedulesList.remove(SchedulesRVModal(schedulesList[viewHolder.adapterPosition].scheduleName, schedulesList[viewHolder.adapterPosition].scheduleId))
                      }, 200)
                  }
              }
          }
          val touchHelper = ItemTouchHelper(swipeSchedule)
          touchHelper.attachToRecyclerView(binding.selectDeviceList)
  </code></pre>
  <p>And this is how I add new items:</p>
  <pre><code>        binding.addSchedule.setOnClickListener {
              var schName = &quot;0&quot;
              var schId = 0
              //lateinit var schList: ArrayList&lt;SchedulesRVModal&gt;
  
              if(schedulesList.isNotEmpty()) {
                  schName = schedulesList[schedulesList.lastIndex].scheduleName
                  schId = schedulesList[schedulesList.lastIndex].scheduleId + 1
              }
              schedulesList.add(SchedulesRVModal(schName, schId))
              adapter.notifyDataSetChanged()
  
              val sharedPreferences = getSharedPreferences(&quot;shared preferences&quot;, MODE_PRIVATE)
  
              val editor = sharedPreferences.edit()
              val gson = Gson()
              val json: String = gson.toJson(schedulesList)
              editor.putString(&quot;schedules&quot;, json)
              editor.apply()
          }
  </code></pre>
  <p>The link leads to the video which shows what exactly wrong with adapterPosition I get.
  <a href="https://drive.google.com/file/d/1eePDN9UAPWiAPduEV5JevgYrCISIO3t-/view?usp=sharing" rel="nofollow noreferrer">https://drive.google.com/file/d/1eePDN9UAPWiAPduEV5JevgYrCISIO3t-/view?usp=sharing</a></p>
  <p>I would be grateful for any help.</p>