Vote count:
0
I used this article
How do I modify this code for:
- Limiting the history of searches to 50 ? (performance concerns here)
- Disabling inserts of duplicates for the value "search" (UI experience here)
Here are my two classes:
MySQLiteHelper.java
public class MySQLiteHelper extends SQLiteOpenHelper {
public static final String TABLE_SEARCHES = "searches";
public static final String COLUMN_ID = "_id";
public static final String COLUMN_SEARCH = "search";
private static final String DATABASE_NAME = "searches.db";
private static final int DATABASE_VERSION = 1;
// Database creation sql statement
private static final String DATABASE_CREATE = "create table "
+ TABLE_SEARCHES + "(" + COLUMN_ID
+ " integer primary key autoincrement, " + COLUMN_SEARCH
+ " text not null);";
public MySQLiteHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase database) {
database.execSQL(DATABASE_CREATE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(MySQLiteHelper.class.getName(),
"Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS " + TABLE_SEARCHES);
onCreate(db);
}
}
Search.java
public class Search {
private long id;
private String search;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getSearch() {
return search;
}
public void setSearch(String search) {
this.search = search;
}
// Will be used by the ArrayAdapter in the ListView
@Override
public String toString() {
return search;
}
}
asked 34 secs ago
Android: Implement SQLite max number of history + no duplicate entries
Aucun commentaire:
Enregistrer un commentaire