2012-11-08 269 views

回答

1

要獲得使用從日期選取器日期此

DatePicker datePicker = (DatePicker) findViewById(R.id.datePicker1); 
int day = datePicker.getDayOfMonth(); 
int month = datePicker.getMonth() + 1; 
int year = datePicker.getYear(); 

設定值數據庫

public void onDateSet(DatePicker view,int year,int monthOfYear,int dayOfMonth){ 
      dateTime.set(year,monthOfYear,dayOfMonth); 

    int year = year; // Here you can get day,month and year. 
    int month = monthOfYear; 
    int day = dayOfMonth; 

ContentValues values = new ContentValues() 

values.put("Day",dayOfMonth); 
values.put("Month",monthOfYear); 
values.put("Year",year); 

} 

你可以從數據庫教程hereherehere

爲了得到當前日期

String currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date()); 

設置提醒 可以使用alaram管理器來設置提醒的解決方案,可以發現here

EDIT 2

private class myReminderTask extends AsyncTask<Void, Void, Void>{ 
    ArrayList<String> list = new ArrayList<String>(); 
    @Override 
    protected Void doInBackground(Void... params) { 
     while(true) 
     for(String s : list){ 
      Date d = //Make date from the string obtained from SQL 
      d.toString().equals(DateFormat.getDateTimeInstance().format(new Date())); 

      //Create an alaram or notification 
     } 

     return null; 
    } 

    @Override 
    protected void onPreExecute() { 

     Cursor c = null; 
     c = db.rawQuery("select startDate,endDate from tablename" , null); 

     if (cursor.getCount() != 0) 
      { 
       if (cursor.moveToFirst()) 
       { 
        do 
        { 
         list.add(cursor.getString(cursor.getColumnIndex("FirstDate"))); 
         list.add(cursor.getString(cursor.getColumnIndex("LastDate"))); 
        } while (cursor.moveToNext()); 
       } 
       db.closeDatabase(); 
      } 
      cursor.close(); 

     super.onPreExecute(); 
    } 

} 

AsyncTaskexample here also)上做整個事情,以便主UI線程不被阻塞,在預執行代碼數據庫獲取和在後臺做使用while循環,以便它永不結束

這就是我可以讓休息你做的工作...就這些,休息你必須尋找和你的方式不要指望我做,並給整個項目

+0

謝謝你,我完成插入stratDate和fromDate在表。但我無法獲取日期並檢查當前日期,並在應用程序打開時顯示一條提醒消息 – Narendra

+0

從數據庫檢索數據http://anujarosha.wordpress.com/2011/12/19/how-to-retrieve- data-from-a-sqlite-database-in-android /然後將它存儲在字符串和'currentDateTimeString .equals(date_retrieved_from_database)'中,如果它的真實值顯示提醒 –

+0

謝謝,你能給我任何代碼演示來獲取日期在字符串數組中存儲,然後將其與當前日期進行比較 – Narendra

相關問題