我目前在我的 Android 应用程序上遇到时间排名问题。我正在使用 sqlite
数据库,该数据库将存储用户完成 解决问题的时间。稍后我将使用该 sqlite
数据库来显示玩该游戏的用户的排名。
例如,玩家完成拼图的时间约为 1:25 (1 分 25 秒),应用程序会将 1:25
存储在 sqlite 数据库中。但我在这样做时遇到了问题。
我可以将它作为
string
存储在sqlite
上,但我不能使用ORDER 通过
。我尝试将其存储为
int
但输出显示:invalidint
我尝试将其存储为
string
,同时删除冒号 (:),但数据库返回“125”。
我的问题是:在sqlite
数据库中存储特定时间值的最佳方式是什么?
我读了this http://www.sqlite.org/lang_datefunc.html有关时间和日期函数的文档,但它似乎不能应用于自定义时间。它仅适用于现在日期或当前时间。请我在这方面需要帮助。我是一个 android 和 sqlite 业余爱好者。这个项目是我本学期的论文。
接受任何意见和建议。提前致谢!
顺便说一下,这是检索我的 sqlite 上所有数据的代码。这是一个测试程序,用于测试我的代码/修改代码并查看它们是否正常工作。
try {
String selectQuery = "SELECT * FROM " + DatabaseHelper.TABLE_OUTLET + " WHERE category LIKE '" + cat + "' ORDER BY category ASC";
Cursor cursor = db.rawQuery(selectQuery, null);
if (cursor.getCount() > 0) {
while (cursor.moveToNext()) {
// Read columns data
int outlet_id = cursor.getInt(cursor.getColumnIndex("outlet_id"));
String outlet_name = cursor.getString(cursor.getColumnIndex("outlet_name"));
String outlet_type = cursor.getString(cursor.getColumnIndex("outlet_type"));
String category = cursor.getString(cursor.getColumnIndex("category"));
// dara rows
TableRow row = new TableRow(context);
row.setLayoutParams(new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT,
TableLayout.LayoutParams.WRAP_CONTENT));
String[] colText = {outlet_name, outlet_type, category};
for (String text : colText) {
TextView tv = new TextView(this);
tv.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
TableRow.LayoutParams.WRAP_CONTENT));
tv.setGravity(Gravity.CENTER);
tv.setTextSize(16);
tv.setPadding(5, 5, 5, 5);
tv.setText(text);
row.addView(tv);
}
tableLayout.addView(row);
}
}
db.setTransactionSuccessful();
} catch (SQLiteException e) {
e.printStackTrace();
} finally {
db.endTransaction();
// End the transaction.
db.close();
// Close database
}
}
最佳答案
1:25
仅将其转换为秒。
即 1 * 60 + 25 = 85
。所以存储 85
。
每次你想存储它时都这样做。您可以在恢复时执行相反的操作。
例如,
sec = 85 % 60 = 25
min = 85 / 60 = 1
你将得到 1:25
关于java - 安卓时间排行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42252147/