我按照這個教程http://www.sarahghaffary.com/android-quotes-generator-sample-application-using-alarmmanager-and-sqlite-database/,但我想知道如何使它即使用完引號也不斷重複引號。我知道我需要更改下面的代碼,但不知道如何。只有初學者,任何幫助都會很棒!重複相同的活動
代碼:
public String getRandomQuote(){
SQLiteDatabase db = this.getWritableDatabase();
String selectQuery = "SELECT * FROM " + QUOTES_TABLE_NAME + " WHERE " + KEY_ISREAD + " = 0 ORDER BY RANDOM() LIMIT 1";
Cursor cursor = db.rawQuery(selectQuery, null);
if (cursor != null)
if(cursor.moveToFirst()){
db.execSQL("update " + QUOTES_TABLE_NAME + " set " + KEY_ISREAD + " = 1 where "+ KEY_ID +" = "+ cursor.getString(0));
return cursor.getString(1);
}
return "Sorry, you ran out of quotes <img src="http://www.sarahghaffary.com/wp-includes/images/smilies/icon_biggrin.gif" alt=":D" class="wp-smiley"> ";
}
簡單的解決方案是再次把KEY_ISREAD回0。 – njzk2
我該怎麼做? – user2407147
就像你把它放到1一樣,只是沒有where子句。 – njzk2