我有一个带有CardView的RecyclerView。我可以创建卡,我可以从该卡插入数据到我的数据库。现在我可以删除这个CardView。如何从数据库中删除CardView?
谢谢!抱歉我的英语不好:)
CardViewAdapter的片段
public void onBindViewHolder(final ViewHolder holder, final int position) {
CardViewDebt card = mDataset.get(position);
holder.mWho.setText(card.getWho());
holder.mWhom.setText(card.getWhom());
holder.mWhat.setText(card.getTarget());
holder.mStart.setText(card.getStartYear() + "/" + (card.getStartMonth() + 1) + "/" + card.getStartDay());
holder.mEnd.setText(card.getEndYear() + "/" + (card.getEndMonth() + 1) + "/" + card.getEndDay());
holder.checkbox.setChecked(false);
holder.checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked) {
DBHelper DataBase = new DBHelper(holder.mContext);
SQLiteDatabase db = DataBase.getWritableDatabase();
Log.d("Delete row in Database", "--- Delete from mytable: ---");
db.delete("debt", "id = " + position, null); <----Thats wrong
mDataset.remove(position);
notifyItemRemoved(position);
notifyItemRangeChanged(position, mDataset.size());
}
}
});
}