最先就从数据库开始吧,首先必须搞清楚数据库的结构,后面的工作才好开展。
我希望用一张表记录所有的单词不管是四级还是托付,它就相当于一个单词池(好拗口),每个单词可以映射到不同的书里面,比如一个单词它可以是四级词汇,同时也是托付词汇,我们就不用重复记录这个单词。
就目前看来,我们需要3张表:
单词表:记录所有的单词,包括写法,音标,词性,解释,读音(暂时没这个,但是还是暂一位),解释,例句,单词的重要程度。够完整了吧,难道还要加上同义词和反义词?以后再说吧。
学习计划表: 此表记录当前学习的是那本书,学习单词的小组数(每本书不可能一次就学完吧,分成若干小组便于学习), 当前学到哪一组。
书表: 记录书名和单词数。
代码如下:
单词表:
- public class WordTable extends Table{
- public static final String TABLE_NAME = "vocabulary";
- public static final String COLUMN_NAME_WORD = "word";
- public static final String COLUMN_NAME_SYMBOL = "symbol";
- public static final String COLUMN_NAME_TRANSLATION = "translation";
- public static final String COLUMN_NAME_PRONUNCIATION = "pronunciation";
- public static final String COLUMN_NAME_EXAMPLES = "examples";
- public static final String COLUMN_NAME_BOOKS = "books";
- public static final String COLUMN_NAME_STUDY_COUNT = "study_count";
- public static final String COLUMN_NAME_MISTAKE_COUNT = "mistake_count";
- public static final String COLUMN_NAME_SEARCH_COUNT = "search_count";
- public static final String COLUMN_NAME_LEVEL = "level";
- public static void createTable(SQLiteDatabase db) {
- db.execSQL("CREATE TABLE IF NOT EXISTS" + TABLE_NAME + " ("
- + COLUMN_NAME_ID + " INTEGER PRIMARY KEY,"
- + COLUMN_NAME_WORD + " TEXT,"
- + COLUMN_NAME_SYMBOL + " TEXT,"
- + COLUMN_NAME_TRANSLATION + " TEXT,"
- + COLUMN_NAME_PRONUNCIATION + " TEXT,"
- + COLUMN_NAME_EXAMPLES + " TEXT,"
- + COLUMN_NAME_BOOKS + " TEXT,"
- + COLUMN_NAME_STUDY_COUNT + " INTEGER,"
- + COLUMN_NAME_MISTAKE_COUNT + " INTEGER,"
- + COLUMN_NAME_SEARCH_COUNT + " INTEGER,"
- + COLUMN_NAME_LEVEL + " INTEGER"
- + ");");
- }
- public static void dropTable(SQLiteDatabase db) {
- db.execSQL("DROP TABLE " + TABLE_NAME);
- }
- }
书本表:
- public class BookTable extends Table {
- public static final String TABLE_NAME = "book";
- public static final String COLUMN_NAME_BOOK_NAME = "book_name";
- public static final String COLUMN_NAME_WORD_NUMBER = "word_number";
- public static void createTable(SQLiteDatabase db) {
- db.execSQL("CREATE TABLE IF NOT EXISTS" + TABLE_NAME + " ("
- + COLUMN_NAME_ID + " INTEGER PRIMARY KEY,"
- + COLUMN_NAME_BOOK_NAME + " TEXT,"
- + COLUMN_NAME_WORD_NUMBER + " INTEGER"
- + ");");
- }
- public static void dropTable(SQLiteDatabase db) {
- db.execSQL("DROP TABLE " + TABLE_NAME);
- }
- }
计划表:
- public class PlanTable extends Table {
- public static final String TABLE_NAME = "plan";
- public static final String COLUMN_NAME_BOOKS = "books";
- public static final String COLUMN_NAME_MODE = "mode";
- public static final String COLUMN_NAME_CHAPTER_NUMBER = "chapter_number";
- public static final String COLUMN_NAME_CURRENT_CHAPTER = "current_chapter";
- public static void createTable(SQLiteDatabase db) {
- db.execSQL("CREATE TABLE IF NOT EXISTS" + TABLE_NAME + " ("
- + COLUMN_NAME_ID + " INTEGER PRIMARY KEY,"
- + COLUMN_NAME_BOOKS + " TEXT,"
- + COLUMN_NAME_MODE + " INTEGER,"
- + COLUMN_NAME_CHAPTER_NUMBER + " INTEGER,"
- + COLUMN_NAME_CURRENT_CHAPTER + " INTEGER"
- + ");");
- }
- public static void dropTable(SQLiteDatabase db) {
- db.execSQL("DROP TABLE " + TABLE_NAME);
- }
- }