嗨,我有一個問題。我如何從後向讀取我的Sql數據。我嘗試了很多的事情,我在網上找到,但沒有在這裏工作是我的代碼:從後面讀取Sql數據庫
public Cursor getAllRows() {
String where = null;
Cursor c = db.query(true, DATABASE_TABLE, ALL_KEYS,
where, null, null, null,null,null);
if (c != null) {
c.moveToFirst();
}
return c;
而且光標的代碼:
Cursor cursor = myDb.getAllRows();
// Allow activity to manage lifetime of the cursor.
// DEPRECATED! Runs on the UI thread, OK for small/short queries.
startManagingCursor(cursor);
// Setup mapping from cursor to 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 to may columns of the DB onto elemesnt in the UI.
SimpleCursorAdapter myCursorAdapter =
new SimpleCursorAdapter(
this, // Context
R.layout.item_tagebuch, // Row layout template
cursor, // cursor (set of DB records to map)
fromFieldNames, // DB Column names
toViewIDs // View IDs to put information in
);
// Set the adapter for the list view
ListView myList = (ListView) findViewById(R.id.listView1);
myList.setAdapter(myCursorAdapter);
坦克你的幫助,爲我的壞對不起英語:)
'讀我從backward'的Sql DATAS並不意味着很多,我......你的意思是'我如何以相反的順序顯示數據? –
是:)對不起我不知道怎麼說 – 360Productions
'cursor.moveToLast();'while while(cursor。hasPrevious()){//做你的代碼}' –