I fetch the id of a database table ordered from smallest to largest. The table contains a maximum of 7 records, now I want to set the calendar according to the id taken. In practice, the id smaller sets the calendar to today, tomorrow, the next one and so on until the seventh day. The logic of my if-else seems to hang on the second day. What should I do?
@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