嗨我有這個代碼,它從我創建的SQLite本地數據庫檢索數據。顯示所有抓取的數據SQLite
下面的代碼是一個公共光標來檢索所有我從數據庫
public Cursor RetriveAdvertData (DatabasOpperations DBOpp, String Username, String AdvertType){
SQLiteDatabase SQDB = DBOpp.getReadableDatabase();
String[] Coloumns = {TableData.TableInfo.USERNAME, TableData.TableInfo.ADVERT_NAME, TableData.TableInfo.ADVERT_EMAIL, TableData.TableInfo.ADVERT_ADDRESS, TableData.TableInfo.ADVERT_NUMBER, TableData.TableInfo.ADVERT_TYPE};
String Where = TableData.TableInfo.USERNAME + " LIKE ? AND " + TableData.TableInfo.ADVERT_TYPE + " LIKE ?";
String Argument[] = {Username, AdvertType};
Cursor Cur = SQDB.query(TableData.TableInfo.TABLE_NAME2, Coloumns, Where, Argument, null, null, null);
return Cur;
}
需要的數據,那麼我調用另一個Java頁面
Context Contx = this;
public DatabasOpperations DB = new DatabasOpperations(Contx);
public Cursor Cur;
Cur = DB.RetriveAdvertData(DB, DBUsername, "Restaurant");
String AdName = "";
String AdEmail = "";
String AdAddress = "";
String AdNumber = "";
String AdType = "";
if (Cur.moveToFirst()){
do {
AdName = Cur.getString(Cur.getColumnIndex("AdvertsName"));
AdEmail = Cur.getString(Cur.getColumnIndex("AdvertEmail"));
AdAddress = Cur.getString(Cur.getColumnIndex("AdvertAddress"));
AdNumber = Cur.getString(Cur.getColumnIndex("AdvertNumber"));
AdType = Cur.getString(Cur.getColumnIndex("AdvertType"));
final String[] Adverts = new String[]{
AdName, AdEmail, AdAddress, AdNumber, AdType
};
ArrayAdapter setListAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, Adverts);
LV1.setAdapter(setListAdapter);
}while (Cur.moveToNext());
}
Cur.close();
代碼的功能只顯示一個光標從數據庫中的行,我如何修改代碼以顯示數據庫中的所有行?
如果只顯示一行,因爲要重設每個循環中的適配器。 –
你有什麼建議來解決這個問題? – RexDough
擺脫了嗎?並在 – RexDough