Hey im trying to do something like , when user clicks the button it gets the data from a dataBase column , named Datas in a for loop, it runs the for loop as many time as the maxID (if the max id is 10(10 dates) it runs 10 times) . Well and whit that data it took from that database they setBackgroundDrawableForDate(blue,(that date it took from database)).Its not doing that setBackgroundDrawableForDate and I don't know why. Here is my code :
ClickListener that is called when user clicks the button:
add_test.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
boolean isInserted = myDB.insertData("Portugues", sala_text.getText().toString(), dt, hora2);
if (isInserted){
Toast.makeText(getContext(),"Teste inserido ao calendario",Toast.LENGTH_LONG).show();
date_button.setVisibility(View.VISIBLE);
hora_button.setVisibility(View.VISIBLE);
date_text.setVisibility(View.INVISIBLE);
sala_text.setText("");
}
else{
Toast.makeText(getContext(),"Preencha todos os espaços",Toast.LENGTH_LONG).show();
}
myCF.addToCalendar();
}
});
}
}
Method that is called when user clicks by the ClickListener:
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();
}
}
}
Methods that are called for getting the maxID and all the dates in 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 id){
String date = "";
String last_query = "SELECT " + COL_4 + " FROM " + TABLE_NAME + " WHERE " + COL_1 + " = '" + id + "'";
Cursor c = database.rawQuery(last_query, null);
if (c != null && c.moveToFirst())
{
date = c.getString(0); // Return Value
}
c.close();
return date;
}
}