Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Caldroid whit SQLite #465

Open
Poreis opened this issue Jul 12, 2017 · 0 comments
Open

Using Caldroid whit SQLite #465

Poreis opened this issue Jul 12, 2017 · 0 comments

Comments

@Poreis
Copy link

Poreis commented Jul 12, 2017

So I am using a DataBase whit dates , and I have a code that retrieves the maxID of that database(number of dates) and then , I have a for loop that goes trough the database and selects a date (String) and parses it in to a date and the sets the background for that date on the calendar . The problem is that its not setting the background for blue.

The code that gets the maxID and the Dates from the database :
` 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;
}

}`

The code that uses those methods and setTHEbackgroundColor for each of those dates: ` 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();
        }
    }
}

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant