Ciao a tutti, nella mia applicazione Android utilizzo un database con 2 Tabelle, la tabella A può avere da 1 a 7 records:
codice:Tabella A _id - campo1 1 testo 2 testo 3 testo 4 testo 5 testo 6 testo 7 testo
La tabella B è composta dall'id, dall' id della tabella A e un altro campo:
Ora, prelevo i dati dalle tabelle con il LEFT JOIN e in base all'id della tabella A aggiungo i giorni al calendario in questo modo:codice:La tabella B è composta dall'id, dall' id della tabella A e un altro campo: Tabella B _id - id_tabella_A - campo3 1 2 testo 2 3 testo 3 5 testo 4 1 testo 5 7 testo
Il problema nasce quando l'id non è in sequenza ad esempio: (1,3,5,6,7,8,9)codice:@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 " + .... .... "FROM Tabella a " + "LEFT JOIN TabellaB b ON (a._id = b.id_tabella_A) " + "ORDER BY a._id ASC"; Cursor cur = db.rawQuery(tabella_op, null); while (cur.moveToNext()) { id_a = cur.getInt(0); giorno_ok= cur.getInt(1); if (id_a == 1) { startTime.set(Calendar.DAY_OF_MONTH, giorno_ok); } else if (id_a == 2) { startTime.set(Calendar.DAY_OF_MONTH, giorno_ok); startTime.add(Calendar.DATE, 1); } else if (id_a == 3) { startTime.set(Calendar.DAY_OF_MONTH, giorno_ok); startTime.add(Calendar.DATE, 2); } else if (id_a == 4) { startTime.set(Calendar.DAY_OF_MONTH, giorno_ok); startTime.add(Calendar.DATE, 3); } else if (id_a == 5) { startTime.set(Calendar.DAY_OF_MONTH, giorno_ok); startTime.add(Calendar.DATE, 4); } else if (id_a == 6) { startTime.set(Calendar.DAY_OF_MONTH, giorno_ok); startTime.add(Calendar.DATE, 5); } else if (id_a == 7) { startTime.set(Calendar.DAY_OF_MONTH, giorno_ok); startTime.add(Calendar.DATE, 6); } } cur.close(); db.close(); ... ... }
In pratica a prescindere dal numero dell'id (sono ordinati in ordine crescente), il primo deve aggiungere un giorno, il secondo id 2 giorni, il terzo id 3 giorni e così via.
Grazie per i vostri suggerimenti

Rispondi quotando