示例#1
0
  public int updateByID(Alarm alarm) {
    liteDB = getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put("title", alarm.getTitle());
    values.put("hour", alarm.getHour());
    values.put("minute", alarm.getMinute());
    values.put("music_path", alarm.getMusic_path());
    values.put("extra_data", alarm.getExtra_data());
    values.put("sonn_time", alarm.getSonn_time());

    return liteDB.update(TABLE_NAME, values, "id", new String[] {alarm.getId() + ""});
  }
示例#2
0
  /**
   * 添加
   *
   * @param alarm
   * @return
   */
  public long save(Alarm alarm) {
    liteDB = getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put("title", alarm.getTitle());
    values.put("hour", alarm.getHour());
    values.put("minute", alarm.getMinute());
    values.put("music_path", alarm.getMusic_path());
    values.put("extra_data", alarm.getExtra_data());
    values.put("sonn_time", alarm.getSonn_time());

    return liteDB.insert(TABLE_NAME, null, values);
  }
示例#3
0
  /**
   * 获取所有结果集
   *
   * @return
   */
  public ArrayList<Alarm> getAll() {
    ArrayList<Alarm> alarms = new ArrayList<Alarm>();
    liteDB = getReadableDatabase();
    cursor = liteDB.query(TABLE_NAME, null, null, null, null, null, null);
    if (cursor.getCount() > 0) {
      Alarm tempAlarm;
      while (cursor.moveToNext()) {
        tempAlarm = new Alarm();
        tempAlarm.setId(cursor.getInt(cursor.getColumnIndex("id")));
        tempAlarm.setTitle(cursor.getString(cursor.getColumnIndex("title")));
        tempAlarm.setExtra_data(cursor.getString(cursor.getColumnIndex("extra_data")));
        tempAlarm.setMusic_path(cursor.getString(cursor.getColumnIndex("music_path")));
        tempAlarm.setSonn_time(cursor.getInt(cursor.getColumnIndex("sonn_time")));
        tempAlarm.setHour(cursor.getInt(cursor.getColumnIndex("hour")));
        tempAlarm.setMinute(cursor.getInt(cursor.getColumnIndex("minute")));

        alarms.add(tempAlarm);
      }
    }
    return alarms;
  }