我这样做了,但是没有用.我到了force close.
public boolean favoriteDelete(int id) {
return database.delete("FavoriteData", "Google" + "=" + id, null) > 0;
}
Run Code Online (Sandbox Code Playgroud) 我用a sqlite表示数据.单击一行弹出一行,提示用户从我的活动中删除单行:ListViewCustomListAdapteralert dialoguesqlite
private void deleteDialog() {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(MyCart.this);
alertDialog.setCancelable(false);
alertDialog.setMessage("Delete item?");
alertDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
myDb.deleteSingleContact(toString());
}
});
alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
alertDialog.show();
}
Run Code Online (Sandbox Code Playgroud)
在我的DBHelper.java上:
public void deleteSingleContact(String title){
SQLiteDatabase db = this.getWritableDatabase();
db.delete(CONTACTS_TABLE_NAME, CONTACTS_COLUMN_TITLE + "=?", new String[]{title});
//KEY_NAME is a column name
}
Run Code Online (Sandbox Code Playgroud)
但是上面的代码没有删除任何东西.我猜它的功能我没有正确完成.任何建议?
完整的DBHelper.java
public class DBHelper extends SQLiteOpenHelper {
public …Run Code Online (Sandbox Code Playgroud)