我終於成功地在數據庫中添加了另一列,但現在不知道如何取出它!這是一個提醒應用程序和信息被傳遞給報警管理器類在這裏我需要從數據庫中獲得值
public class ReminderManager {
private Context mContext;
private AlarmManager mAlarmManager;
public ReminderManager(Context context) {
mContext = context;
mAlarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
}
public void setReminder(Long taskId, Calendar when) {
Intent i = new Intent(mContext, OnAlarmReceiver.class);
i.putExtra(RemindersDbAdapter.KEY_ROWID, (long)taskId);
PendingIntent pi = PendingIntent.getBroadcast(mContext, 0, i, PendingIntent.FLAG_ONE_SHOT);
mAlarmManager.set(AlarmManager.RTC_WAKEUP, when.getTimeInMillis(), pi);
}
}
它拉信息從數據庫中,並通過意圖從我的編輯活動發送這裏(簡稱代碼)
private void saveState() {
String title = mTitleText.getText().toString();
String body = mBodyText.getText().toString();
SimpleDateFormat dateTimeFormat = new SimpleDateFormat(DATE_TIME_FORMAT);
String reminderDateTime = dateTimeFormat.format(mCalendar.getTime());
if (mRowId == null) {
long id = mDbHelper.createReminder(title, body, reminderDateTime, spinInterval);
if (id > 0) {
mRowId = id;
}
} else {
mDbHelper.updateReminder(mRowId, title, body, reminderDateTime, spinInterval);
}
new ReminderManager(this).setReminder(mRowId, mCalendar);
}
設置報警的最後一行。我添加了一個微調器,讓用戶選擇鬧鐘的頻率。我會將其更改爲setRepeating並添加來自微調器的值。我有他們在數據庫中選擇這裏
database picture http://www.bthindiet.com/database.jpg
如果ID3中的最後一項保存和傳遞到我的ReminderManager類設定報警值,我怎麼能提取該行的spinInterval值5小時?我想採取該字符串,然後我將它轉換爲(60 * 60 * 1000 * 5)的時間爲setRepeating。
我希望你能幫忙!!
我認爲它會更容易來聲明spinInterval爲整數且只保留小時(2,4,5等數)。 只需在代碼中動態添加「Every」..「hours」標籤即可。 – 2013-05-11 01:51:14