0

I want to make a memo which was dated, I input the date with activities in a separate place from the calendar. How do I display all events in the calendar according to the date that I fed?

public List<Foto> getAllFotoList() {
        List<Foto> fotoList = new ArrayList<Foto>();

        String query_tb_foto = "SELECT * FROM " + TABLE_FOTO;

        // SQLiteDatabase db = this.getWritableDatabase();
        Cursor cursor = db.rawQuery(query_tb_foto, null);

        if (cursor.moveToFirst()) {
            do {
                // Siswa siswa = new Siswa(cursor.getString(0),
                // cursor.getString(1));
                Foto foto = new Foto(cursor.getString(cursor
                        .getColumnIndexOrThrow("COL_JUDULFT")),
                        cursor.getString(cursor
                                .getColumnIndexOrThrow("COL_IMG")),
                        cursor.getString(cursor
                                .getColumnIndexOrThrow("COL_DESFT")),
                        cursor.getString(cursor
                                .getColumnIndexOrThrow("COL_STARTDATEFT")),
                        cursor.getString(cursor
                                .getColumnIndexOrThrow("COL_STARTTIMEFT")),
                        cursor.getString(cursor
                                .getColumnIndexOrThrow("COL_ENDDATEFT")),
                        cursor.getString(cursor
                                .getColumnIndexOrThrow("COL_ULANGFT")),
                        cursor.getString(cursor
                                .getColumnIndexOrThrow("COL_ALARMFT")));
                fotoList.add(foto);
            } while (cursor.moveToNext());
            return fotoList;
        }
        return null;
    }

Is this true? Thanks for respons.

umindul
  • 1
  • 2

2 Answers2

0

You need to use something like SELECT * FROM some_table WHERE date('1990-01-01'); (Just insert your custom date). This should return all of the results from your table with the same date value. See this post for further explanation and the SQLite documentation to see what else you can do with dates.

Two answer your second question, using a ListView should be fine. I personally use an ArrayList to populate my ListViews for SQLite results since queries return an arbitrary number of results. An ArrayList makes it easy to store and access those results.

Community
  • 1
  • 1
Don
  • 506
  • 2
  • 8
  • 23
0

did you sore the date as a GMTTIMESTAMP? if so

 String Q= "SELECT * FROM "+TABLE_FOTO +" ORDER BY GMTTIMESTAMP DESC;"; 

will put all the rows of the data with the most recent at the front.

or you could reference it by your primary key?

I was always told to make sure you remember to put a semicolon in side the brackets or your leave yourself open to SQL injections.

and you always want to check for null cursors so you should also have

if(cursor!=null&&cursor.moveToFirst()){}

Mark Gilchrist
  • 1,972
  • 3
  • 24
  • 44
  • So this query `String Q= "SELECT * FROM "+TABLE_FOTO +" ORDER BY GMTTIMESTAMP DESC;";` call the columns `COL_STARTDATEFT` of my table `TABLE_FOTO` ?? – umindul Jun 09 '13 at 04:55
  • Do I need to add some code in my calendar menu? I'm confused by the logic of the algorithm :) – umindul Jun 09 '13 at 04:57
  • are COL_STARTDATEFT or COL_STARTTIMEFT timestamps or strings, so did you enter them as "currentSystemTime()"(which is a gmttimestamp something like 103774000) or are you string them as strings? – Mark Gilchrist Jun 09 '13 at 11:58