相关疑难解决方法(0)

如何从SQLite android中的表中删除一行?

我这样做了,但是没有用.我到了force close.

public boolean favoriteDelete(int id) {
    return database.delete("FavoriteData", "Google" + "=" + id, null) > 0;
}
Run Code Online (Sandbox Code Playgroud)

sqlite android

17
推荐指数
2
解决办法
3万
查看次数

如何删除android sqlite中的单行

我用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)

sqlite android

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

android ×2

sqlite ×2