I have a code that uses SQL, and in that database, I have a column of dates, then I have a code that returns the maxID (number of rows, or number of dates) and I have another code which goes to that column and returns the date with the ID specified in the parameter. To this "work" I have a method which does is loop through the method that returns the date with the ID specified in the parameter, and then with that date uses a Caldroid method, setBackgroundDrawable.
Well, the problem is that it is not working, but it has no error.
Code of methods that return the maxID and the ID date (x):
public int getLastId() {
String query = "SELECT MAX(id) AS max_id FROM " + TABLE_NAME;
Cursor cursor = database.rawQuery(query, null);
int id = 0;
if (cursor.moveToFirst())
{
do
{
id = cursor.getInt(0);
} while(cursor.moveToNext());
}
cursor.close();
return id;
}
public String getDates(int numero){
String date = "";
String last_query = "SELECT " + COL_4 + " FROM " + TABLE_NAME + " WHERE " + COL_1 + " = '" + numero + "'";
Cursor c = database.rawQuery(last_query, null);
if (c != null && c.moveToFirst())
{
date = c.getString(c.getColumnIndex("DIA")); // Return Value
}
c.close();
return date;
}
}
method that calls these two methods with a loop:
public void addToCalendar(){
myDB = CustomApplication.getDatabaseHelper();
ColorDrawable blue = new ColorDrawable(Color.BLUE);
for(int i=0;i == myDB.getLastId();i++){
String dt = myDB.getDates(i);
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("dd-MM-yyyy");
Date teste = null;
try {
teste = sdf.parse(dt);
caldroidFragment.setBackgroundDrawableForDate(blue,teste);
} catch (ParseException e) {
e.printStackTrace();
}
}
}