dimanche 27 septembre 2015

Android set calendar from database data

through a method I get all the id in a table and insert them in a list sorted from smallest to largest:

private void AddId(){
    SQLiteDatabase db = new DatabaseHelper(getActivity()).getReadableDatabase();
    String sql= "SELECT _id FROM TabellaA ORDER BY _id ASC";
    Cursor cur = db.rawQuery(sql, null);
    while (cur.moveToNext()) {
        int Nid = cur.getInt(0);
        arrayId.add(Nid);
    }
    cur.close();
    db.close();
}

Now, in another list, I fetch data from another database table that has a field in it (idTabellaA) which is the id of TabellaA, and inside I added a loop that would add a day calendar, whenever the id changes, give an example of what I get:

TabellaA
_id
1
2
3
TabellaB
_id - idTabellaA
1    -    1
2   -     1
3    -    2
4   -     2
5   -     2
6   -     3

When I fetch the data from TabellaB, if it is the first idTabellaA taken, I want to set the calendar with the date of today, if the next id drawn is greater than that of first I want to set the calendar with the date of today + 2, if the next id taken is greater than the first I want to set the calendar with the date of today + 3, and so on....

This is what I have done so far, but I do not get the desired result because its useful for seems to recognize only the second day.

@Override
public List<WeekViewEvent> onMonthChange(int newYear, int newMonth) {
    int varAppoggio = 0;
    int varAppoggioId = 0;
   String tabella_op = "SELECT idTabellaA ........";
   Cursor cur = db.rawQuery(tabella_op, null);
    while (cur.moveToNext()) {
           id_ = cur.getInt(0);
         for (int i = 0; i<arrayId.size(); i++){
            if(varAppoggio == 0){
                varAppoggio = arrayId.get(i);
                varAppoggioId = id_ ;
                startTime.set(Calendar.DAY_OF_MONTH, 27);
            }else if(varAppoggio < arrayId.get(i)&& varAppoggioId < id_ ){
                startTime.add(Calendar.DATE, 1);
                varAppoggioId = id_ ;
            }
        }

}

    cur.close();
    db.close();
    return events;
}

Aucun commentaire:

Enregistrer un commentaire