im getting dates from database see database:
im loding dates in array list i want tocheck if current date exist in arraylistthen print title of that day how i will do that?
static ArrayList Vacation_ID = new ArrayList();
static ArrayList Vacation_name = new ArrayList();
static ArrayList Vacation_Date = new ArrayList();
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
Solved
You are storing the date in an array list so, you will need to check every element of array list if the string containing matches the date specified by you.
Compare the ArrayList values as follows:-
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";
}
use below code
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+"' ");
i think it is work please check this link for database operation this

No comments:
Post a Comment