2013-11-02 155 views
-1
在ArrayList和顯示messgae日期從數據庫

即時得到日期見數據庫:在數組列表我想,如果當前日期在該arraylistthen打印標題存在tocheck如何找到數據庫

image

IM裝載儀日期那天我會怎麼做?

   static ArrayList<String> Vacation_ID = new ArrayList<String>(); 
static ArrayList<String> Vacation_name = new ArrayList<String>(); 
static ArrayList<String> Vacation_Date = new ArrayList<String>(); 


      Cursor mCursor3 = db.selectQuery("SELECT * FROM uss_vacation WHERE calendar_id = 
       '"+Calendar_id+"' "); 


    if (mCursor3.moveToFirst()) { 
     do { 



    Vacation_ID.add(mCursor3.getString(mCursor3.getColumnIndex("id"))); 

      Vacation_name.add(mCursor3.getString(mCursor3.getColumnIndex("title"))); 

      Vacation_Date.add(mCursor3.getString(mCursor3.getColumnIndex("date"))); 


     } while (mCursor3.moveToNext()); 
    } 


    mCursor3.close(); 


      now i want to check if current date exist in araylist Vacation_Date show title 
    of that date like 
      if (Vacation_Date.contains("2013-11-11")) { 
       string datetitle; 
        datetitle="Veterans Day" from database 
+0

你存儲日期字符串在數據庫..? –

+0

是的所有是STRING – user2947238

+0

其中日期格式像dd-MM-yyyy或任何東西..? –

回答

-1

下面的代碼

Date dt = new Date(); 
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); 
    String check = dateFormat.format(dt); 
Cursor mCursor3 = db.selectQuery("SELECT * FROM uss_vacation WHERE calendar_id = 
      '"+check+"' "); 

使用我認爲這是工作 請查看此鏈接,數據庫操作this

+0

幫我在這裏http:///stackoverflow.com/questions/19740124/android-how-to-terminate-functionand-return-to-asyntask-after-getting-spesific-v我的充分senario那裏 – user2947238

0

你存儲的日期在數組列表,這樣,您將需要如果包含的字符串與您指定的日期相匹配,請檢查數組列表的每個元素。

比較ArrayList的值如下: -

String datetitle = ""; 
for (int index = 0; index< Vacation_Date.size();index++) 
{ 
    String date = Vacation_Date.get(index); 
    if(date.contains("2013-11-11")); 
    //datetitle = "your value"; 
}