java - Reading Sql Database from backward -
hey guy have question. how can read sql datas backward. tried lot of things found in net nil works here code:
public cursor getallrows() { string = null; cursor c = db.query(true, database_table, all_keys, where, null, null, null,null,null); if (c != null) { c.movetofirst(); } homecoming c; and code cursor:
cursor cursor = mydb.getallrows(); // allow activity manage lifetime of cursor. // deprecated! runs on ui thread, ok small/short queries. startmanagingcursor(cursor); // setup mapping cursor view fields: string[] fromfieldnames = new string[] {dbadapter.key_kalo, dbadapter.key_hydrate, dbadapter.key_fat, dbadapter.key_protein ,dbadapter.key_cal}; int[] toviewids = new int[] {r.id.item_kalorien, r.id.item_kg_in_g, r.id.item_f_in_g, r.id.item_p_in_g,r.id.item_cal}; // create adapter may columns of db onto elemesnt in ui. simplecursoradapter mycursoradapter = new simplecursoradapter( this, // context r.layout.item_tagebuch, // row layout template cursor, // cursor (set of db records map) fromfieldnames, // db column names toviewids // view ids set info in ); // set adapter list view listview mylist = (listview) findviewbyid(r.id.listview1); mylist.setadapter(mycursoradapter); tank helping, , sorry bad english:)
the statement "from backward" ambiguous assuming want read db in particular order
if want read in descending order of field 'foo' then
string order = "foo desc";/*use asc ascending order*/
and alter cod follows
public cursor getallrows() { string = null; string order = "foo desc"; cursor c = db.query(true, database_table, all_keys, where, null, null, null,order,null); if (c != null) { c.movetofirst(); } homecoming c; here syntax of query
public cursor query (string table, string[] columns, string selection,string[] selectionargs, string groupby, string having, string orderby, string limit)
refer below link farther explanantion sqlitedatabase android
java android sql database cursor
No comments:
Post a Comment