예제 #1
0
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "notes-db", null);
        db = helper.getWritableDatabase();
        daoMaster = new DaoMaster(db);
        daoSession = daoMaster.newSession();
        noteDao = daoSession.getNoteDao();

        String textColumn = NoteDao.Properties.Text.columnName;
        String orderBy = textColumn + " COLLATE LOCALIZED ASC";
        cursor = db.query(noteDao.getTablename(), noteDao.getAllColumns(), null, null, null, null, orderBy);
        String[] from = { textColumn, NoteDao.Properties.Comment.columnName };
        int[] to = { android.R.id.text1, android.R.id.text2 };

        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_2, cursor, from,
                to);
        setListAdapter(adapter);

        editText = (EditText) findViewById(R.id.editTextNote);
        addUiListeners();
    }
예제 #2
0
    private void addNote() {
        String noteText = editText.getText().toString();
        editText.setText("");

        final DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);
        String comment = "Added on " + df.format(new Date());
        Note note = new Note(null, noteText, comment, new Date());
        noteDao.insert(note);
        Log.d("DaoExample", "Inserted new note, ID: " + note.getId());

        cursor.requery();
    }
 @Override
 public void deleteLaboratory(int id) throws ServiceEntityNotFoundException {
   try {
     gradeDao.deleteGradesByLaboratory(id);
     attendanceDao.deleteAttendancesByLaboratory(id);
     documentDao.deleteDocumentsByLaboratory(id);
     laboratoryDao.deleteLaboratoryById(id);
     noteDao.deleteNotesByLaboratory(id);
   } catch (DaoEntityNotFoundException e) {
     LOGGER.debug("DaoEntityNotFoundException");
     throw new ServiceEntityNotFoundException(e);
   }
 }
예제 #4
0
 @Override
 protected void onListItemClick(ListView l, View v, int position, long id) {
     noteDao.deleteByKey(id);
     Log.d("DaoExample", "Deleted note, ID: " + id);
     cursor.requery();
 }