private void updateTaskList() { // clear list tasks.clear(); Cursor taskQuery = taskOpenHelper.getAllTasks(); // if there are tasks in query then add them to list if (taskQuery.moveToFirst()) { Task t; do { try { // create a new task t = new Task(); // and set parameters t.set_id(taskQuery.getInt(TaskOpenHelper.DB_TASK_TABLE_KEY_ID_COLUMN)); t.setLabel(taskQuery.getString(TaskOpenHelper.DB_TASK_TABLE_KEY_LABEL_COLUMN)); t.setDatetime(taskQuery.getString(TaskOpenHelper.DB_TASK_TABLE_KEY_DATE_COLUMN)); t.setCompleted(taskQuery.getInt(TaskOpenHelper.DB_TASK_TABLE_KEY_COMPLETED_COLUMN)); t.setPriority(taskQuery.getInt(TaskOpenHelper.DB_TASK_TABLE_KEY_PRIORITY_COLUMN)); t.setNote(taskQuery.getString(TaskOpenHelper.DB_TASK_TABLE_KEY_NOTES_COLUMN)); // add task to list tasks.add(t); } catch (Exception e) { Log.e(TAG, e.getMessage()); } } while (taskQuery.moveToNext()); } taskQuery.close(); fillListData(); }
@Override protected void onPause() { super.onPause(); taskOpenHelper.close(); }
@Override protected void onStart() { super.onStart(); taskOpenHelper.openDatabase(); }