[英]How to retrieve data from specific row SQLiteAssetHelper
如何通過其ID檢索特定數據並在textview中顯示它們? 而不是檢索數據並在列表視圖中顯示所有數據。 請幫忙!
公共類KaikaiProfileActivity擴展了ListActivity {
private Cursor animals;
private MyDatabase db;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
db = new MyDatabase(this);
animals = db.getAnimals(); // you would not typically call this on the main thread
ListAdapter adapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_2,
animals,
new String[] {"animalName","animalPersonality"},
new int[] {android.R.id.text1, android.R.id.text2});;
getListView().setAdapter(adapter);
}
@Override
protected void onDestroy() {
super.onDestroy();
animals.close();
db.close();
}
//檢索所有數據如何從特定行檢索數據? 公共游標getAnimals(){
SQLiteDatabase db = getReadableDatabase();
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
String [] sqlSelect = {"0_id", "animalName", "animalInfo","ImageName","animalGender","animalDOB",
"animalDOB", "animalBirthPlace", "animalPersonality", "animalFeatures", "animalFood", "animalPastTime"
};
String sqlTables = "AnimalInfo";
qb.setTables(sqlTables);
Cursor c = qb.query(db, sqlSelect, null, null,
null, null, null);
c.moveToFirst();
return c;
}
使用c.moveToPosition(int index)
代替c.moveToFirst()
以獲取該特定索引處的記錄
例如,如果要返回第一條記錄,請使用c.moveToPosition(0)
,第二條記錄請使用c.moveToPosition(1)
,依此類推
如果qb.appendWhere("<colname>=<value>") ;
列值檢索,請使用qb.appendWhere("<colname>=<value>") ;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.