Android的db.delete();在ListActivity [英] Android db.delete(); on ListActivity
问题描述
我需要的事帮助...
I need help on a matter...
我创建了一个连接到我的数据库,并显示出我,我救了我的表中的所有内容的列表cursord适配器列表视图。
我后来创建了以longckick出现在所需的行的上下文菜单
I created a listview with a cursord adapter that connects to my database,and shows me a list of everything that I saved in my table. I later created a context menu that appears with longckick on the desired line
上下文位置
id = getListAdapter().getItemId(info.position);
这是我的方法在databaseHelper删除
this is my method delete in the databaseHelper
void deleteReg(SQLiteDatabase db)
{
db.delete(TabellaRegistry.TABLE_NAME,null, null);
}
和我使用,在我的删除所选行活动:
and i use that in my activity for delete the selected line:
final SQLiteDatabase db = databaseHelper.getWritableDatabase();
databaseHelper.deleteReg(db,null, null, null, null, null, null);
但这样做...我删除所有我的表...
but doing so...i delete all in my table...
我怎么通过上下文菜单只删除选定的行?
how do I delete only the selected line via the context menu?
我希望我解释自己,在此先感谢
I hope I explained myself, thanks in advance
推荐答案
通过传递NULL作为你的第二个参数在这条线:
By passing NULL as your second argument on this line:
db.delete(TabellaRegistry.TABLE_NAME,null, null);
您总是会删除整个表。由于Android文档中提及,参数如下:
You will always be deleting the whole table. As mentioned in the Android documentation, the parameters are as following:
公众诠释删除(字符串表,字符串whereClause,字符串[] whereArgs)
表 - 表从删除
whereClause - 选购时删除WHERE子句适用。
传递null将删除所有行。
whereClause - the optional WHERE clause to apply when deleting. Passing null will delete all rows.
因此,让我们说你要删除的行,其中BOOK_ID是6,你会碰到这样的:
So let's say you want to delete the line where BOOK_ID is 6 you would have something like:
public boolean deleteTitle(String id)
{
return db.delete(DATABASE_TABLE, BOOK_ID + "=" + id, null) > 0;
}
SQLite的类概述:的http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html
这篇关于Android的db.delete();在ListActivity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!