-1

我从数据库中获取日期请参阅数据库:

图片

我在数组列表中输入日期我想检查当前日期是否存在于数组列表中然后打印当天的标题我将如何做到这一点?

                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
4

2 回答 2

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";
}
于 2013-11-02T08:12:14.347 回答
-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+"' ");

我认为这是工作请检查此链接以进行数据库操作

于 2013-11-02T07:57:15.590 回答