问题我有一个数据库,其中包含一个动物表,其中包含_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