我使用listview创建了一个Radio应用程序。数据存储在sqlite db上。如果我使用“DB Browser for Sqlite”将新工作站添加到sqlite上的新工作站,新工作站将到达最后一个位置,因为它按id.example数字排序100位于第100位。我希望它按名称排序,如站在名字A开头的第一名。这是我的StationDBHandler:
public StationDBHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
setForcedUpgrade();
}
/**
*
* @return list station
*/
public ArrayList<Station> getAllStations() {
ArrayList<Station> stationArrayList = new ArrayList<>();
String selectQuery = "SELECT * FROM " + StationTable.stationTable;
db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
if (cursor.moveToFirst()) {
do {
Station station = new Station();
station.setId(cursor.getInt(cursor.getColumnIndex(StationTable.id)));
station.setName(cursor.getString(cursor.getColumnIndex(StationTable.name)));
station.setLogo(cursor.getString(cursor.getColumnIndex(StationTable.logo)));
station.setGenre(cursor.getString(cursor.getColumnIndex(StationTable.genre)));
station.setLongDesc(cursor.getString(cursor.getColumnIndex(StationTable.longDesc)));
station.setStreamUrl(cursor.getString(cursor.getColumnIndex(StationTable.streamUrl)));
stationArrayList.add(station);
} while (cursor.moveToNext());
}
cursor.close();
return stationArrayList;
}
答案 0 :(得分:0)
您可以使用SQLiteDatabase.query()
方法
Cursor cursor = db.query("TABLE_NAME",new String[]{"COLUMN1","COLUMN2","COLUMN3"},null,null,null,null,"COLUMN1 ASC");