title: RecyclerView with LayoutBinding - Swipe to remove - Leaves empty space of item size
body: <p>I have searched a lot online but apparently unable to find answer.  I have a todo list, and the adapter has swipe functionality attached, so when someone swipes the item it removes the item from the list.</p>
  <p>The problem is that the item that is removed is replaced by new item, but that area is shown as empty area.</p>
  <p><a href="https://i.stack.imgur.com/V7jdi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/V7jdi.png" alt="enter image description here" /></a></p>
  <p>I know there is row item there but does not show up, if I close app and open again it will show up.</p>
  <p>Here is my adapter class.</p>
  <pre><code>@Suppress(&quot;NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS&quot;)
  class TodoAdapter(var allTodos: ArrayList&lt;Todo&gt;, var callback: iTodoAdapter)
  : RecyclerView.Adapter&lt;TodoAdapter.TodoViewHolder&gt;(),
  ItemTouchHelperCustomListener {
  
  //Hello
  override fun onItemDismiss(position: Int) {
      callback.onDelete(position)
  }
  
  override fun onItemMove(fromPosition: Int, toPosition: Int) : Boolean {
      callback.onItemsSwapped(fromPosition, toPosition)
      return true
  }
  
  override fun updateDatabasePositions(fromPosition: Int, toPosition: Int) {
      val size = allTodos.size - 1
      for (index in 0..size) {
          allTodos.get(index).position = index
      }
      callback.onPositionsUpdated()
  }
  
  
  override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) : TodoViewHolder {
      val binding = LayoutTodoItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
      return TodoViewHolder(binding)
  }
  
  override fun getItemCount(): Int {
      return allTodos.size
  }
  
  private fun createOnClickListener(position: Int) : View.OnClickListener {
      return View.OnClickListener {
          val checked = (it as CheckBox).isChecked
          allTodos.get(position).isSelected = checked
          allTodos.get(position).let { callback.onItemUpdated(it) }
      }
  }
  
  
  override fun onBindViewHolder(holder: TodoViewHolder, position: Int) {
      holder.bind(allTodos.get(position), createOnClickListener(position))
  }
  
  //We only have 1 type of item
  override fun getItemViewType(position: Int): Int {
      return position
  }
  
  class TodoViewHolder(private val binding : LayoutTodoItemBinding) :
      RecyclerView.ViewHolder(binding.root) {
  
      fun bind(todoItem : Todo?, clickListner: View.OnClickListener) {
          binding.apply {
              setTodoItem(todoItem)
              onClickListener = clickListner
              executePendingBindings()
          }
      }
  }
  
  fun getData() : ArrayList&lt;Todo&gt; {
      return this.allTodos
  }
  
  
  interface iTodoAdapter {
      fun onDelete(position: Int)
      fun onItemsSwapped(from: Int, to: Int)
      fun onPositionsUpdated()
      fun onItemUpdated(item: Todo)
  }
  }
  </code></pre>
  <p>Here is my iTodoAdapter implemented in my fragment</p>
  <pre><code>override fun onDelete(position: Int) {
      viewModel.delete(allTodos.get(position))
  }
  
  override fun onItemsSwapped(from: Int, to: Int) {
      Collections.swap(allTodos, from, to)
      rcyTodo?.adapter?.notifyDataSetChanged()
  }
  
  override fun onPositionsUpdated() {
      viewModel.updateAll((rcyTodo?.adapter as TodoAdapter).getData())
  }
  
  override fun onItemUpdated(item: Todo) {
      viewModel.update(item)
  }
  </code></pre>
  <p>Here is my fragment setup:</p>
  <pre><code>    val dividerItemDecoration = DividerItemDecoration(rcyTodo.context,DividerItemDecoration.VERTICAL)
      rcyTodo.addItemDecoration(dividerItemDecoration)
  
      rcyTodo.apply {
          adapter = TodoAdapter(allTodos, this@Todo)
          setHasFixedSize(true)
      }
  
      setupSwipeToDelete()
      setCurrentItems()
  </code></pre>
  <p>Here are the functions</p>
  <pre><code>private fun setupSwipeToDelete() {
      val itemTouchHelperCallback = ItemTouchHelperCallback(rcyTodo.adapter as TodoAdapter)
      val itemTouchHelper = ItemTouchHelper(itemTouchHelperCallback)
      itemTouchHelper.attachToRecyclerView(rcyTodo)
  }
  
  @SuppressLint(&quot;CheckResult&quot;)
  private fun setCurrentItems() {
      viewModel.getAllTodos().subscribe({
          allTodos.clear()
          allTodos.addAll(it)
          rcyTodo?.recycledViewPool?.clear()
          rcyTodo?.adapter?.notifyDataSetChanged()
      }, {
  
      })
  }
  </code></pre>
  <p>I found somewhere that clearing a pool (rcyTodo?.recycledViewPool?.clear()) should redraw items but does not work.</p>
  <p>I am thinking do I have to remove layout binding and do it in simple way? is there a way around it? am I missing something? By the way the empty space does have item, this only happens when I remove one item after swiping. Something to do with drawing elements, somehow recycler view thinks this position is should be empty.</p>