我必须在列表视图上显示保存的 sqlite 数据。但是只有一列的数据就足够了。这是我的代码。我想获取“tarih”列的数据。
public class TarihDataSource {
private SQLiteDatabase database;
private DatabaseOlusturma dbOlustur;
private String []allColumns = {"tarih","gunluknotu","resim"};
public TarihDataSource(Context context) {
dbOlustur = new DatabaseOlusturma(context);
}
public void open() throws SQLException {
database = dbOlustur.getReadableDatabase();
}
public void close() {
dbOlustur.close();
}
public List<TarihListHelper> getAllTarih() {
List<TarihListHelper> tarihlistesi = new ArrayList<TarihListHelper>();
Cursor cursor = database.query("gunluker", allColumns, null, null,
null, null, null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
TarihListHelper comment = cursorToComment(cursor);
tarihlistesi.add(comment);
cursor.moveToNext();
}
// Make sure to close the cursor
cursor.close();
return tarihlistesi;
}
private TarihListHelper cursorToComment(Cursor cursor) {
TarihListHelper comment = new TarihListHelper();
comment.setTarih(cursor.getString(1));
return comment;
}
}
这段代码有什么问题?