Example #1
0
  // @SuppressWarnings("deprecation")
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

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

    String textColumn = LogsDao.Properties.Notes.columnName;
    // String orderBy = textColumn + " COLLATE LOCALIZED ASC";

    cursor =
        db.query(
            noteDao.getTablename(),
            noteDao.getAllColumns(),
            null,
            null,
            null,
            null,
            null /*orderBy*/);
    String[] from = {textColumn, LogsDao.Properties.Hours.columnName};
    int[] to = {R.id.textView1, R.id.textView2};

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

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

    float tempFloat = Float.parseFloat(editHours.getText().toString());
    // tempFloat *= (10/6);
    editHours.setText("");

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

    cursor.requery();
  }
Example #3
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();
 }