ユーザーの単語を記憶できる辞書を作っていますが、単語リストを100語程度に制限したいと思います。この単語リストを制限するにはどうすればよいですか?私はそれをするためにいくつかの情報を見つけようとしましたが、それは難しいようです。私を助けてください!これは私のデータベース作成方法です:
public class DataProvider extends SQLiteOpenHelper {
// Database Version
private static final int DATABASE_VERSION = 1;
// Database Name
private static final String DATABASE_NAME = "contactsManager";
// Contacts table name
private static final String TABLE = "contacts";
public DataProvider(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
// Contacts Table Columns names
private static final String KEY_NAME = "name";
private static final String KEY_DECRIBED = "described";
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE + "("
+KEY_NAME + " TEXT,"
+ KEY_DECRIBED + " TEXT" + ")";
db.execSQL(CREATE_CONTACTS_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
db.execSQL("DROP TABLE IF EXISTS " + TABLE);
// Create tables again
onCreate(db);
}
public void addContact(Name contact) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_NAME, contact.getName()); // Contact Name
values.put(KEY_DECRIBED, contact.getDescribed()); // Contact Described
// Inserting Row
db.insert(TABLE, null, values);
db.close(); // Closing database connection
}
// Getting single contact
public Name getContact(int id) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE, new String[] {
KEY_NAME, KEY_DECRIBED },
null, new String[] { String.valueOf(id) }, null, null, null, null);
if (cursor != null)
cursor.moveToFirst();
Name contact = new Name(cursor.getString(0),
cursor.getString(1));
// return contact
return contact;
}
public List<Name> getAllContacts() {
List<Name> contactList = new ArrayList<Name>();
// Select All Query
String selectQuery = "SELECT * FROM " + TABLE;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
Name contact = new Name();
contact.SetName(cursor.getString(0));
contact.SetDescribed(cursor.getString(1));
// Adding contact to list
contactList.add(contact);
} while (cursor.moveToNext());
}
// return contact list
return contactList;
}
// Getting contacts Count
public int getContactsCount() {
String countQuery = "SELECT * FROM " + TABLE;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(countQuery, null);
cursor.close();
// return count
return cursor.getCount();
}
}