【发布时间】:2018-03-26 10:29:19
【问题描述】:
我使用 listview 制作了一个 Radio 应用程序。数据存储在 sqlite db 上。如果我使用“DB Browser for Sqlite”通过 sqlite 向应用程序添加新电台,则新电台排在最后,因为它按 id.example 编号排序100 排在第 100 位。我希望它按名称排序,例如以名称 A 开头的 Station。这是我的 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;
}
【问题讨论】:
-
而且您从未尝试过搜索“sqlite 排序”之类的内容?
-
当然,您没有正确搜索。我会给你一个提示你可以找到你的答案here
-
为什么不直接使用其他
SQLiteDatabase方法query(String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy);
标签: java android sqlite sorting