我想通过单击recyclerview项目从sqlite db返回链接。 它始终返回最后添加的内容。问题在于光标,但我不知道,如何修复它。
DBManager.class中的游标查询
public Cursor linkColumn() {
String[] linkColumn = new String[]{DatabaseHelper.LINK};
Cursor cursor = sqLiteDatabase
.query(
DatabaseHelper.TABLE_NAME,
linkColumn,
null,
null,
null,
null,
null);
return cursor;
}
点击商品
@Override
public void onItemClick(long _id) {
Intent returnIntent = new Intent();
Cursor cursor = dbManager.linkColumn();
String item = cursor.getString(cursor.getColumnIndex(DatabaseHelper.LINK));
returnIntent.putExtra("link", item);
setResult(RESULT_OK, returnIntent);
finish();
}
答案 0 :(得分:0)
DBManager.class中的游标查询
public Cursor linkColumn(long _id) {
String[] itemById = new String[]{DatabaseHelper.LINK};
Cursor cursor = sqLiteDatabase
.query(
DatabaseHelper.TABLE_NAME,
itemById,
DatabaseHelper.ID + "=" + _id,
null,
null,
null,
null);
if (cursor != null) {
cursor.moveToFirst();
}
return cursor;
}
点击商品
@Override
public void onItemClick(long _id) {
Intent returnIntent = new Intent();
Cursor cursor = dbManager.linkColumn(_id);
if(cursor.getCount()!=0){
String item = cursor.getString(cursor.getColumnIndex(DatabaseHelper.LINK));
returnIntent.putExtra("link", item);
setResult(RESULT_OK, returnIntent);
finish();}
cursor.close();
}