0

with this query I get a list of records from the database, and I order them according to the id, from smallest to largest. Now when the id of the query will change, compared to the previous, I want to add a day to the calendar. How can I do?

@Override
public List<WeekViewEvent> onMonthChange(int newYear, int newMonth) {
List<WeekViewEvent> events = new ArrayList<WeekViewEvent>();
SQLiteDatabase db = new DatabaseHelper(getActivity()).getReadableDatabase();
    String tabella_op = "SELECT id_operatore FROM Table ORDER BY id_operatore ASC";
    Cursor cur = db.rawQuery(tabella_op, null);
 while (cur.moveToNext()) {
id_operator = cur.getInt(0);

 Calendar startTime = Calendar.getInstance();
//////////////////////////part of the code for the date change
if(op_confronto == id_operator){
            startTime = Calendar.getInstance();
        }else if(id_operator > op_confronto){
            startTime.add(Calendar.DATE, 1);
            op_confronto = id_operator;
        }
////////////////////////////
...
...
}
    cur.close();
    db.close();
    return events;

}
JJkk
  • 133
  • 1
  • 9

1 Answers1

0

Save your id_operator in Shared Preferences always when you make your select.

Check if the select value is equal than your saved id in Shared Preferences and if it is add the day with the code below.

You have an example of using Shared Preferences here.

You have here an example about how to add a day to a calendar in java:

String dt = "2008-01-01";  // Start date
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
c.setTime(sdf.parse(dt));
c.add(Calendar.DATE, 1);  // number of days to add
dt = sdf.format(c.getTime());  // dt is now the new date
Community
  • 1
  • 1
João Marcos
  • 3,872
  • 1
  • 19
  • 14