android sqlite delte,在Android中删除SQLite中的行

这可能是一个愚蠢的问题,但是我是SQLite的新手,我似乎无法弄清楚。我有了列1台KEY_ROWID,KEY_NAME,KAY_LATITUDE,和KEY_LONGITUDE。我希望用户能够选择一个并删除它;谁能给我一个开始的方向?我的问题是仅给定名称的行的实际删除。

相关代码:

public class BeaconDatabase {

public static final String KEY_ROWID = "_id";

public static final String KEY_NAME = "beacon_name";

public static final String KEY_LATITUDE = "beacon_lat";

public static final String KEY_LONGITUDE = "beacon_lon";

private static final String DATABASE_NAME ="BeaconDatabase";

private static final String DATABASE_TABLE ="beaconTable";

private static final int DATABASE_VERSION = 1;

private DbHelper helper;

private final Context context;

private SQLiteDatabase db;

public BeaconDatabase(Context context) {

this.context = context;

}

public BeaconDatabase open() {

helper = new DbHelper(this.context);

db = helper.getWritableDatabase();

return this;

}

public void close() {

helper.close();

}

public long createEntry(String name, Double lat, Double lon) {

ContentValues cv = new ContentValues();

cv.put(KEY_NAME, name);

cv.put(KEY_LATITUDE, lat);

cv.put(KEY_LONGITUDE, lon);

return db.insert(DATABASE_TABLE, null, cv);

}

public void deleteEntry(long row) {

// Deletes a row given its rowId, but I want to be able to pass

// in the name of the KEY_NAME and have it delete that row.

//db.delete(DATABASE_TABLE, KEY_ROWID + "=" + row, null);

}

public String getData() {

String[] columns = { KEY_ROWID, KEY_NAME, KEY_LATITUDE, KEY_LONGITUDE };

Cursor cursor = db.query(DATABASE_TABLE, columns, null, null, null, null, null);

String result = "";

int iRow = cursor.getColumnIndex(KEY_ROWID);

int iName = cursor.getColumnIndex(KEY_NAME);

int iLat = cursor.getColumnIndex(KEY_LATITUDE);

int iLon = cursor.getColumnIndex(KEY_LONGITUDE);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值