I'm populating a list with the calendar days, according to the id of a database table. I fetch the ID, in ascending order and check them to a variable of type int, with each iteration of the cursor if the ID is larger, add one or more days, but all appear on the same date, what is wrong?
@Override
public List<WeekViewEvent> onMonthChange(int newYear, int newMonth) {
int n = 0;
String sql = ".....ORDER BY _id ASC";
Cursor cur = db.rawQuery(sql , null);
while (cur.moveToNext()) {
startTime = (Calendar) calendarioFooter.clone();
id_ = cur.getString(0);
if(n == 0){
n = id_ ;//1
startTime.set(Calendar.DAY_OF_MONTH, 21);
}else if(id_ > n){
n = id_ ;//2
startTime.set(Calendar.DAY_OF_MONTH, 21);
startTime.add(Calendar.DATE, 1);
}else if(id_ > n){
n = id_ ;//3
startTime.set(Calendar.DAY_OF_MONTH, 21);
startTime.add(Calendar.DATE, 2);
}else if(id_ > n){
n = id_ ;//4
startTime.set(Calendar.DAY_OF_MONTH, 21);
startTime.add(Calendar.DATE, 3);
}else if(id_ > n){
n = id_ ;//5
startTime.set(Calendar.DAY_OF_MONTH, 21);
startTime.add(Calendar.DATE, 4);
}else if(id_ > n){
n = id_ ;//6
startTime.set(Calendar.DAY_OF_MONTH, 21);
startTime.add(Calendar.DATE, 5);
}else if(id_ > n){
n = id_ ;//7
startTime.set(Calendar.DAY_OF_MONTH, 21);
startTime.add(Calendar.DATE, 6);
}
...
...
}
Aucun commentaire:
Enregistrer un commentaire