問題我有一個數據庫,其中包含一個動物表,其中包含_id,name,biography的列。Android:與SQLite查詢
我想根據用戶選擇的動物(從列表中)查詢特定傳記的數據庫,問題是遊標只會返回數據庫中的第一個傳記,或根本沒有。
任何人都可以看到問題可能是什麼,或提供一些有用的建議,我會非常感激。
// Code for obtaining position
protected void onListItemClick(ListView l, View v, int position, long id){
Intent animalIntent = new Intent(this, Animal.class);
animalIntent.putExtra("pos", position);
startActivity(animalIntent);
}
//查詢數據庫中的bio,其中KEY_ROWID是通過列表中項目的「位置」查詢的。 myCursor = dbm.getBio(position);
if(myCursor.moveToFirst()){
// querying the cusor, retrieve in index of column BIOGRAPHY, store as column index.
int bio_index = myCursor.getColumnIndexOrThrow(MyDBManager.KEY_BIOGRAPHY);
// return the string from the cursor @ column index
String bio = myCursor.getString(bio_index);
// find textview
animalBio = (TextView)findViewById(R.id.bio);
// Set textView to value of string returned from myCursor @ bio_index
animalBio.setText(bio);
}
//該方法總是返回
return qmDB.query(ANIMAL_TABLE, new String[]{
KEY_ROWID,
KEY_BIOGRAPHY,
},
KEY_ROWID,
null,
null,
null,
null);
}
存儲在數據庫中存儲的 公共光標getBio(INT位置)中的數據庫的基礎資料的第一個值{I已經嘗試其它變化如KEY_ROWID =「+」= position,KEY_ROWID =「?」,將位置轉換爲字符串,傳入位置爲long類型,硬編碼數字等。
所以,你看到我感覺問題在於查詢語句,它根本不會返回任何其他比第一行還是IF,它不顯示!
SOLUTION:
記得在應用程序上更新您的數據庫。
你能否提供獲取'position'的代碼? – pecka85 2011-04-25 11:06:11
肯定pecka,我已經更新了與代碼原來的職位,還有一些關於我如何解決問題的新解釋。 – Jnanathan 2011-04-25 13:41:24
我已經設法解決了這個問題,因爲事實證明我沒有更新DB.4天和無數小時的沮喪感,不會忘記這一點,感謝大家提供有用的建議。 – Jnanathan 2011-04-25 14:27:41