我正在做一个项目,我想在 ListView 中显示机场列表。从本地数据库中检索机场名称。实际上我在 sqliteopenhelper 类中从数据库中获取所有数据
public List<AirportList> getAllAirportLists()
{
List<AirportList> airportList = new ArrayList<AirportList>();
String selectQuery = "SELECT * FROM " + TABLE_AIRPORT;
Log.i("query", selectQuery);
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
if(cursor.moveToFirst())
{
do{
AirportList airport = new AirportList();
airport.setId(Integer.parseInt(cursor.getString(0)));
airport.setName(cursor.getString(1));
}while(cursor.moveToNext());
}
return airportList;
}
我是 android 新手,任何人都可以提供一个想法,以便在主类中调用此方法并在列表视图中显示机场列表。