使用sqlite kotlin的回收者视图

问题描述 投票:1回答:1

我正在尝试删除SQLite DB注释,并使用kotlin,并且渲染由recyclerview完成。但是我的删除无法完成工作,不是删除。对此很新,请帮助。

持有人类别

class MyHolder (Itemview : View):RecyclerView.ViewHolder(Itemview) {

var titleHolder: TextView = Itemview.findViewById(R.id.tv_title)

var descriptionHolder: TextView = Itemview.findViewById(R.id.tv_content)

var imgEditHolder: ImageView = Itemview.findViewById(R.id.im_edit)

var imgDeleteHolder: Button = Itemview.findViewById(R.id.im_delete)  
}


Adapter Onbindervieewholder  method


override fun onBindViewHolder(holder: MyHolder, position: Int) {

            var Mynotes = noteLiist[position]

            holder.titleHolder.text = Mynotes.nodeTitle
            holder.descriptionHolder.text = Mynotes.nodeDescritption
            holder.imgDeleteHolder.setOnClickListener {
                View.OnClickListener {
                    val dbManager = SqlDBManager(this.context!!)
                    val selectionArgs = arrayOf(Mynotes.nodeID.toString())
                    dbManager.Delete("ID=?", selectionArgs)
                    LoadQuery("%")
                }
            }

        }



[![db manager class][1]][1]


  [1]: https://i.stack.imgur.com/D6SjZ.png
android sqlite kotlin android-recyclerview adapter
1个回答
0
投票

初始化数据库类后,在onClickListener上,执行以下操作:

val data = dbManager.DatabaseHelperNotes(context).writableDatabase
data.delete("table_name","where clause",null)
© www.soinside.com 2019 - 2024. All rights reserved.