2013-05-11 19 views
0

我終於成功地在數據庫中添加了另一列,但現在不知道如何取出它!這是一個提醒應用程序和信息被傳遞給報警管理器類在這裏我需要從數據庫中獲得值

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。

我希望你能幫忙!!

+0

我認爲它會更容易來聲明spinInterval爲整數且只保留小時(2,4,5等數)。 只需在代碼中動態添加「Every」..「hours」標籤即可。 – 2013-05-11 01:51:14

回答

1

您最好以整數形式插入spinInterval列。所以,而不是"Every 5 hours"它只會是5.它會更容易。

但是,如果你想使用當前的格式,那麼只是得到字符串「每5小時」,然後解析字符串中的數字。因爲它似乎你spinerInterval字符串格式始終是相同的,那麼你可以很容易地分析

String s = s.subString(6,7); 
+0

我同意將它作爲int插入然後將setRepeating設置爲(60 * 60 * 1000 * s)會更容易?我想我不明白(6,7)部分。我需要抓住當前保存的項目來設置鬧鐘。示例中保存的最後一條記錄具有id#3。對不起,我的無知! – JeffK 2013-05-11 14:25:03

+0

@JeffK 6,7是得到子字符串..在你的第6個數字位置有數字..所以從那裏解析 – stinepike 2013-05-11 16:27:03