vendredi 6 novembre 2015

MoveToNext MoveToPrevious buttons and display record SQLite Android

I am trying to move to and display the next query result, the examples I have seen refer to things like count = 1 or get all records, but can't work out how they are implemented.

I am able to display the first record fine, but when trying to moveToNext I end up at the last result, and moveToPrev does nothing. (I'm guessing this has to do with the count variable I've read about)

DBHelper.Java

public Cursor get_Record (String description,SQLiteDatabase sqlitedatabase) { String selection = DESCRIPTION+" LIKE ?"; String [] selection_args = {"%"+description+"%"}; Cursor c = sqlitedatabase.query(TABLE_NAME, All_Cols, selection, selection_args, null, null, null); return c; }

MainActivity.Java - MoveToNext button

public void btn_ParamNext(View view) { dbhelper = new DbHelper(getApplicationContext()); sqlitedatabase = dbhelper.getReadableDatabase(); Cursor c = dbhelper.get_Record(Desc, sqlitedatabase); while (c.moveToNext()) { DisplayData(c); } c.close(); }

MainActivity.Java - MoveToPrevious button

public void ParamPrev(View view) { dbhelper = new DbHelper(getApplicationContext()); sqlitedatabase = dbhelper.getReadableDatabase(); Cursor c = dbhelper.get_Record(Desc, sqlitedatabase); while (c.moveToPrevious()) { DisplayData(c); } c.close(); }

Other examples I have seen refer to RawQuery, which I have hot been able to get to work at all.

Any help or examples would be very appreciated.

Thanks

Aucun commentaire:

Enregistrer un commentaire