I need to get all of records from TABLE_NOTES, Here is my method for calling all of records:
public List<NotesFragmentCreate> getAllNotes() {
List<NotesFragmentCreate> notes = new ArrayList<NotesFragmentCreate>();
String selectQuery = "SELECT * FROM " + TABLE_NOTES;
SQLiteDatabase db = this.getReadableDatabase();
Cursor c = db.rawQuery(selectQuery, null);
if (c.moveToFirst()) {
do {
NotesFragmentCreate n = new NotesFragmentCreate();
n.setId(c.getInt(c.getColumnIndex(KEY_ID_NOTES)));
n.setTitle(c.getString(c.getColumnIndex(KEY_TITLE)));
n.setCreated(c.getString(c.getColumnIndex(KEY_CREATED)));
n.setContent(c.getString(c.getColumnIndex(KEY_CONTENT)));
// adding to note list
notes.add(n);
} while (c.moveToNext());
}
return notes;
}
Then I create arrays in other class:
String[] title,created,content;
db = new DatabaseHelper(getActivity());
List<NotesFragmentCreate> allNotes = db.getAllNotes();
for (NotesFragmentCreate note : allNotes) {
//how can I get each of record to store in this array?
title[?] = note.getTitle();
created[?] = note.getCreated();
content[?] = note.getContent();
}
Because I want to impement those arrays in a listView
adapter = new ListNotesAdapter(getActivity(), title, created);
Aucun commentaire:
Enregistrer un commentaire