title: how to remove item from recycler view android kotlin
body: <p>i am working with Kotlin , when i removing the item from Recyclerview then it shuffling the items of list there is how i coded. I worked the same in java but it work very fine in java. but in kotlin it creating problems.</p>
  
  <pre><code>                mylist.removeAt(position)
                  notifyItemRemoved(position)
                  notifyItemRangeChanged(position,mylist.size)
  </code></pre>
  
  <p>this is my code for removing the item in adapter
  below how i set the data in my list</p>
  
  <pre><code>                class Gallery_adm_adp(
  val mylist: ArrayList&lt;Model_class_one&gt;,
  val fragmentActivity: FragmentActivity,
  val pages: Int
        ) :
        RecyclerView.Adapter&lt;Gallery_adm_adp.Viewholder&gt;() {
        var currentpage = 2
        lateinit var loadmore: RelativeLayout
         lateinit var image: ImageView
           lateinit internal var edit_menu: ImageView
  
  
  inner class Viewholder(itemView: View) : RecyclerView.ViewHolder(itemView) {
  
      @SuppressLint("ShowToast")
      fun mydata(list: Model_class_one?, position: Int) {
          edit_menu = itemView.findViewById(R.id.edit_menu)
          Log.i("List_check", "running position&gt;&gt; " + position)
          loadmore.visibility = View.GONE
  
          Glide.with(fragmentActivity).load(list!!.Image).into(image)
  
          if (position == mylist.size - 1) {
              if (pages &gt;= currentpage) {
                  loadmore.setVisibility(View.VISIBLE)
                  callnextapi()
              } else {
                  loadmore.setVisibility(View.GONE)
              }
          } else {
              loadmore.setVisibility(View.GONE)
          }
  
          edit_menu.setOnClickListener {
  
  
              val id = list.ID
              popup(itemView, id, position)
              Log.d("clicks", "position" + position)
          }
      }
  }
  
  private fun popup(itemView: View, id: String, position: Int) {
      val popup: PopupMenu
      popup = PopupMenu(fragmentActivity, itemView.edit_menu)
      popup.inflate(R.menu.menu_delete)
      popup.setOnMenuItemClickListener { item -&gt;
          when (item.itemId) {
              R.id.delete -&gt; {
                  showdialog(id, position)
              }
          }
          false
      }
      //displaying the popup
      popup.show()
  }
  
  private fun showdialog(ids: String, position: Int) {
      val builder = AlertDialog.Builder(fragmentActivity)
      builder.setTitle("Delete")
          .setMessage("Do You Want to delete this post")
          .setCancelable(false)
          .setPositiveButton("Yes") { dialog, id -&gt;
              deleteitem(ids, position)
          }.setNegativeButton("No") { dialogInterface, i -&gt;
          }
      val alert = builder.create()
      alert.show()
  }
  
  private fun toast(text: String) {
      ((fragmentActivity as MainActivity_Admin).customtoast(text))
      Toast.makeText(fragmentActivity, text, Toast.LENGTH_SHORT).show()
  }
  
  private fun deleteitem(id: String, position: Int) {
      val requestQueue = Volley.newRequestQueue(fragmentActivity)
      val URL = Constant.DeleteGallery + id
      val stringRequest = object : StringRequest(Request.Method.POST, URL,
          Response.Listener { response -&gt;
              Log.i("VOLLEY_res", "my responce&gt;&gt;$response")
              try {
                  val result = response
                  toast(result)
                  mylist.removeAt(position)
                  notifyItemRemoved(position)
                  notifyItemRangeChanged(position, mylist.size)
  
              } catch (e: JSONException) {
                  e.printStackTrace()
                  toast("Can't Delete .. Please Try Again")
              }
          }, Response.ErrorListener { error -&gt;
              toast("Check Internet Connection and Try Again")
          }) {
      }
      requestQueue.add(stringRequest)
  
  }
  
  
  override fun getItemViewType(position: Int): Int {
      return position
  }
  
  private fun callnextapi() {
      val requestQueue = Volley.newRequestQueue(fragmentActivity)
      val URL = Constant.Gallery + currentpage
  
      val stringRequest = object : StringRequest(Request.Method.POST, URL,
          Response.Listener { response -&gt;
              try {
                  val result = JSONObject(response)
                  val ListDetails = result.getJSONArray("ListDetails")
                  val length = ListDetails.length()
                  for (i in 0 until length) {
                      val objJson = ListDetails.getJSONObject(i)
                      val ID = objJson.getString("ID")
                      val UserName = objJson.getString("UserName")
                      val Image = objJson.getString("Image")
                      val UserID = objJson.getString("UserID")
                      var Date = objJson.getString("Date")
                      Date = Date.replace("12:00:00 AM","")
                      mylist.add(Model_class_one(ID, UserName, Image, UserID,Date))
                  }
                  notifyDataSetChanged()
                  currentpage = currentpage + 1
  
              } catch (e: JSONException) {
                  e.printStackTrace()
              }
          }, Response.ErrorListener { error -&gt;
          }) {
      }
      requestQueue.add(stringRequest)
  
  }
  
  override fun onCreateViewHolder(parent: ViewGroup, p1: Int): Gallery_adm_adp.Viewholder {
      val layout = LayoutInflater.from(fragmentActivity as Context?).inflate(R.layout.gallery_adp_admin, parent, false)
      loadmore = layout.findViewById(R.id.loadmore)
      image = layout.findViewById(R.id.image)
      return Viewholder(layout)
  }
  
  override fun getItemCount(): Int {
      return mylist.size
  }
  
  override fun onBindViewHolder(holder: Gallery_adm_adp.Viewholder, position: Int) {
                val Values = mylist[position]
                  holder.mydata(Values, position)
                }
  
                }
  </code></pre>
  
  <p>//here are some images that you can under stand well how list is shuffling</p>
  
  <p><a href="https://i.stack.imgur.com/2XyEn.png" rel="nofollow noreferrer">my first list</a></p>
  
  <p><a href="https://i.stack.imgur.com/OZyOD.png" rel="nofollow noreferrer">removed that item</a></p>
  
  <p><a href="https://i.stack.imgur.com/wAv6D.png" rel="nofollow noreferrer">changes</a></p>
  
  <p><a href="https://i.stack.imgur.com/48yWx.png" rel="nofollow noreferrer">done again</a></p>
  
  <p><a href="https://i.stack.imgur.com/yPH50.png" rel="nofollow noreferrer">look next step</a></p>
  
  <p><a href="https://i.stack.imgur.com/QxUJg.png" rel="nofollow noreferrer">look next step 6</a></p>
  
  <p><a href="https://i.stack.imgur.com/OnWNB.png" rel="nofollow noreferrer">it showing item even that are removed.. i hope you suggest me good ideas</a></p>
  
  <p>thanks for everyone for helping. i have done all i could please help.</p>