title: how to delete a recycler view item in sqlite database
body: <p>1)in res a layout with two text view and one button and i want to delete an item of recycler view by clicking on button  can u help me please in adapter the </p>
  
  <pre><code>holder.delete.setOnclicklistener{
  //                   what to write here
  
  }
  </code></pre>
  
  <p>2) I have written the delete function in sqlite class</p>
  
  <p>3) I have tried everything its not working
  4)can anyone tell is the delete function in sqlite correct or wrong</p>
  
  <pre><code>class Adapter(var context:Context, data: ArrayList&lt;Subject&gt;):RecyclerView.Adapter&lt;Adapter.ViewHolder&gt;()
  {
      lateinit var db:SQHelper
  
      var data:List&lt;Subject&gt;
      init{
          this.data=data
      }
  
  
      override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
          val layout=LayoutInflater.from(context).inflate(R.layout.item_subject,parent,false)
          return ViewHolder(layout)
      }
  
      @RequiresApi(Build.VERSION_CODES.LOLLIPOP)
      override fun onBindViewHolder(holder: ViewHolder, position: Int) {
          holder.title.text=data[position].title
          holder.id.text=data[position].id
          holder.desc.text=data[position].desc
       holder.delete.setOnClickListener {
  
  }
  
      }
  
      override fun getItemCount(): Int {
          return data.size
      }
  
      class ViewHolder(item: View):RecyclerView.ViewHolder(item)
      {
          internal var title:TextView
          internal var id:TextView
          internal var desc:TextView
  internal var delete:Button
          init {
              title=item.findViewById(R.id.title_textview)
              id=item.findViewById(R.id.id_textview)
              desc=item.findViewById(R.id.desc_textview)
  delete=item.findViewById(R.id.delete_btn)
          }
  
      }
  
  }
  
  
  
  
  //this is adapter
  </code></pre>
  
  <pre><code>class SQHelper(context:Context):SQLiteOpenHelper(context, DB_name,null,1)
  {
  
  
      companion object{ //place where we can add variables
      val DB_name="subjects.db "
          val TB_name="Subject "
          val id="ID"
          val title ="S_title"
          val desc="S_desc"
  
  
  
  
      }
  
      override fun onCreate(db: SQLiteDatabase?) {
          db?.execSQL("create table $TB_name(ID INTEGER PRIMARY KEY AUTOINCREMENT,S_title TEXT,S_desc TEXT)")//execsql will help to prepare table udsyntax
      }
  
      override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) {
          db?.execSQL("DROP TABLE IF EXISTS $TB_name")
      }
      fun ADD_DATA(title_text:String,desc_text:String){
  
          val DB=this.writableDatabase
          val values= ContentValues()
          values.put(title,title_text)
          values.put(desc,desc_text)
          DB.insert(TB_name,null,values)
  
      }
      fun Delete_data(id:String):Int{
         val DB=this.writableDatabase
          val item=DB.delete(TB_name,"id=?", arrayOf(id))
          return item
      }
      val data_getter:Cursor get() {
  
          val DB=this.writableDatabase
          var data=DB.rawQuery("select * from " + TB_name,null)
          return data
      }
  
  
  }
  
  
  
  //this is sqlite
  </code></pre>
  
  <pre><code>this is stack trace
  2020-06-10 23:35:32.274 23159-23159/? I/n.myapplicatio: Late-enabling -Xcheck:jni
  2020-06-10 23:35:32.407 23159-23159/com.wordsforfun.myapplication I/Perf: Connecting to perf service.
  2020-06-10 23:35:32.488 23159-23159/com.wordsforfun.myapplication W/n.myapplicatio: create CommonDcsHelper
  2020-06-10 23:35:32.489 23159-23159/com.wordsforfun.myapplication W/n.myapplicatio: cacheJniMembers success
  2020-06-10 23:35:32.489 23159-23159/com.wordsforfun.myapplication W/n.myapplicatio: constructJavaHashMap: start
  2020-06-10 23:35:32.489 23159-23159/com.wordsforfun.myapplication W/n.myapplicatio: constructJavaHashMap: end
  2020-06-10 23:35:32.489 23159-23159/com.wordsforfun.myapplication W/n.myapplicatio: sendCommonDcs: start
  2020-06-10 23:35:32.490 23159-23159/com.wordsforfun.myapplication W/n.myapplicatio: sendCommonDcs: end
  2020-06-10 23:35:32.490 23159-23159/com.wordsforfun.myapplication W/n.myapplicatio: Accessing hidden method Landroid/view/View;-&gt;getAccessibilityDelegate()Landroid/view/View$AccessibilityDelegate; (light greylist, linking)
  2020-06-10 23:35:32.512 23159-23159/com.wordsforfun.myapplication W/n.myapplicatio: constructJavaHashMap: start
  2020-06-10 23:35:32.512 23159-23159/com.wordsforfun.myapplication W/n.myapplicatio: constructJavaHashMap: end
  2020-06-10 23:35:32.512 23159-23159/com.wordsforfun.myapplication W/n.myapplicatio: sendCommonDcs: start
  2020-06-10 23:35:32.514 23159-23159/com.wordsforfun.myapplication W/n.myapplicatio: sendCommonDcs: end
  2020-06-10 23:35:32.514 23159-23159/com.wordsforfun.myapplication W/n.myapplicatio: Accessing hidden method Landroid/view/View;-&gt;computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection)
  2020-06-10 23:35:32.516 23159-23159/com.wordsforfun.myapplication W/n.myapplicatio: constructJavaHashMap: start
  2020-06-10 23:35:32.516 23159-23159/com.wordsforfun.myapplication W/n.myapplicatio: constructJavaHashMap: end
  2020-06-10 23:35:32.516 23159-23159/com.wordsforfun.myapplication W/n.myapplicatio: sendCommonDcs: start
  2020-06-10 23:35:32.517 23159-23159/com.wordsforfun.myapplication W/n.myapplicatio: sendCommonDcs: end
  2020-06-10 23:35:32.517 23159-23159/com.wordsforfun.myapplication W/n.myapplicatio: Accessing hidden method Landroid/view/ViewGroup;-&gt;makeOptionalFitsSystemWindows()V (light greylist, reflection)
  2020-06-10 23:35:32.523 23159-23159/com.wordsforfun.myapplication W/n.myapplicatio: constructJavaHashMap: start
  2020-06-10 23:35:32.524 23159-23159/com.wordsforfun.myapplication W/n.myapplicatio: constructJavaHashMap: end
  2020-06-10 23:35:32.524 23159-23159/com.wordsforfun.myapplication W/n.myapplicatio: sendCommonDcs: start
  2020-06-10 23:35:32.525 23159-23159/com.wordsforfun.myapplication W/n.myapplicatio: sendCommonDcs: end
  2020-06-10 23:35:32.525 23159-23159/com.wordsforfun.myapplication W/n.myapplicatio: Accessing hidden method Landroid/widget/TextView;-&gt;getTextDirectionHeuristic()Landroid/text/TextDirectionHeuristic; (light greylist, linking)
  2020-06-10 23:35:32.598 23159-23159/com.wordsforfun.myapplication D/OpenGLRenderer: Skia GL Pipeline
  2020-06-10 23:35:32.598 23159-23159/com.wordsforfun.myapplication D/MMListParser: onlineVersion -1 defaultVersion 20191101
  2020-06-10 23:35:32.599 23159-23159/com.wordsforfun.myapplication D/mmscene: open server config failed /data/oppo/multimedia/oppo_display_perf_list.xml
  2020-06-10 23:35:32.600 23159-23159/com.wordsforfun.myapplication D/mmscene: getHint applicationScene=com.wordsforfun.myapplication,idx=0 none
  2020-06-10 23:35:32.617 23159-23159/com.wordsforfun.myapplication D/WindowManager: Add to mViews: DecorView@6f4768[add_subject], this = android.view.WindowManagerGlobal@9934781,pkg=com.wordsforfun.myapplication
  2020-06-10 23:35:32.683 23159-23192/com.wordsforfun.myapplication I/Adreno: QUALCOMM build                   : cb65128, I4f6179b11f
      Build Date                       : 08/15/19
      OpenGL ES Shader Compiler Version: EV031.26.03.02
      Local Branch                     : 
      Remote Branch                    : refs/tags/AU_LINUX_ANDROID_LA.UM.7.11.R1.09.00.00.542.031
      Remote Branch                    : NONE
      Reconstruct Branch               : NOTHING
  2020-06-10 23:35:32.683 23159-23192/com.wordsforfun.myapplication I/Adreno: Build Config                     : S P 6.0.9 AArch64
  2020-06-10 23:35:32.686 23159-23192/com.wordsforfun.myapplication I/Adreno: PFP: 0x016ee183, ME: 0x00000000
  2020-06-10 23:35:32.700 23159-23192/com.wordsforfun.myapplication I/OpenGLRenderer: Initialized EGL, version 1.4
  2020-06-10 23:35:32.700 23159-23192/com.wordsforfun.myapplication D/OpenGLRenderer: Swap behavior 2
  2020-06-10 23:35:32.704 23159-23192/com.wordsforfun.myapplication D/mmscene: getHint applicationScene=com.wordsforfun.myapplication,idx=0 none
  2020-06-10 23:35:32.711 23159-23159/com.wordsforfun.myapplication I/Choreographer: Skipped 3 frames!  The application may be doing too much work on its main thread.
  2020-06-10 23:35:32.761 23159-23159/com.wordsforfun.myapplication I/Choreographer: Skipped 2 frames!  The application may be doing too much work on its main thread.
  
  
  </code></pre>
  
  <pre><code>//main activity
  package com.wordsforfun.myapplication
  
  import android.content.Intent
  import androidx.appcompat.app.AppCompatActivity
  import android.os.Bundle
  import android.widget.Button
  
  class MainActivity : AppCompatActivity() {
      lateinit var miscellaneous: Button
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_main)
          miscellaneous=findViewById(R.id.miscellaneous)
  
          miscellaneous.setOnClickListener {
              startActivity(Intent(this@MainActivity,option::class.java))
          }
  
      }
  }
  </code></pre>
  
  <pre><code>// this is my option class, here in its layout there are two buttons i.e. is add data and saved data .
  package com.wordsforfun.myapplication
  
  import android.content.Intent
  import androidx.appcompat.app.AppCompatActivity
  import android.os.Bundle
  import android.widget.Button
  
  class option : AppCompatActivity() {
  lateinit var add_data:Button
      lateinit var saved_data:Button
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_option)
          add_data=findViewById(R.id.add_data)
          saved_data=findViewById(R.id.saved_data)
          add_data.setOnClickListener {
              startActivity(Intent(this@option,add_subject::class.java))
  
  
          }
          saved_data.setOnClickListener {
  
              startActivity(Intent(this@option,editmiscellenous::class.java))
          }
  
      }
  }
  </code></pre>
  
  <pre><code>//this is my subject class 
  package com.wordsforfun.myapplication
  
  class Subject (var id:String,var title:String,var desc:String)
  
  </code></pre>
  
  <pre><code>// this is my add_subject class, its layout contains two edit text where i can write something to store it in my editmiiscellaneous class
  package com.wordsforfun.myapplication
  
  import android.content.Intent
  import androidx.appcompat.app.AppCompatActivity
  import android.os.Bundle
  import android.widget.Button
  import android.widget.EditText
  import android.widget.Toast
  
  class add_subject : AppCompatActivity() {
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
          setContentView(R.layout.activity_add_subject)
          val DB= SQHelper(applicationContext)
          val title_input=findViewById&lt;EditText&gt;(R.id.title_edit_text)
          val desc_input=findViewById&lt;EditText&gt;(R.id.desc_edit_text)
          val add_btn=findViewById&lt;Button&gt;(R.id.add_btn)
          add_btn.setOnClickListener{
              val title_text=title_input.text.toString().trim()
              val desc_text=desc_input.text.toString().trim()
              DB.ADD_DATA(title_text,desc_text)
              Toast.makeText(this@add_subject,"the subject has been added",Toast.LENGTH_SHORT).show()
              startActivity(Intent(this@add_subject, editmiscellenous::class.java))
  
  
  
          }
  
      }
  }
  </code></pre>
  
  <pre><code>this is editmiscellaneous class where its layout contains recyclerview and go back button
  package com.wordsforfun.myapplication
  
  import android.content.Intent
  import android.database.Cursor
  import android.os.Bundle
  import android.widget.Button
  import android.widget.Toast
  import androidx.appcompat.app.AppCompatActivity
  import androidx.recyclerview.widget.GridLayoutManager
  import androidx.recyclerview.widget.RecyclerView
  import kotlinx.android.synthetic.main.activity_editmiscellenous.*
  
  
  class editmiscellenous : AppCompatActivity() {
  
  lateinit var lists: ArrayList&lt;Subject&gt;
  lateinit var DB: SQHelper
  lateinit var data:Cursor
  
  
  override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      setContentView(R.layout.activity_editmiscellenous)
  
  
      val go =findViewById&lt;Button&gt;(R.id.go)
  
      go.setOnClickListener{
          var intent = Intent(this@editmiscellenous,option::class.java)
          startActivity(intent)}
      lists=ArrayList&lt;Subject&gt;()
      DB= SQHelper(applicationContext)
      data=DB.data_getter
      val adapter=Adapter(applicationContext,lists)
      val recycler=findViewById&lt;RecyclerView&gt;(R.id.list)
      showData()
      list.layoutManager=GridLayoutManager(applicationContext,2)
      list.adapter=adapter
  
  
  }
  fun showData()
  {
      if(data.count==0)
      {
          Toast.makeText(applicationContext,"There is no item",Toast.LENGTH_SHORT).show()
  
      }
  
      while(data.moveToNext()){
          lists.add(Subject(data.getString(0),data.getString(1),data.getString(2)))
  
  
      }
  
  
  
  
  
  }
  
  override fun onStart() {
      super.onStart()
      showData()
  }
  
  
  
  }
  
  
  
  
  
  
  </code></pre>