我想在查询方法中过滤类别和单词匹配

时间:2016-04-29 10:29:58

标签: android sqlite android-studio

我想在查询方法中过滤类别和单词。 现在我进行查询填充词匹配。 这是SQL代码

@Override
public List<Word> getWordListMatchingInCategoryInternet(String matching) {
    String TABLE = Util.getTableName();
    String[] FIELD = new String[]{DictionaryDatabase.COLUMN_ID, DictionaryDatabase.COLUMN_WORD, DictionaryDatabase.COLUMN_MEAN, DictionaryDatabase.COLUMN_FAVORITE,DictionaryDatabase.COLUMN_PIC,DictionaryDatabase.COLUMN_CATEGORY,DictionaryDatabase.COLUMN_HISTORY};
    String WHERE = DictionaryDatabase.COLUMN_WORD +" LIKE ?" ;
    String[] WHERE_ARGS = new String[]{matching + "%"};
    String ORDER_BY = DictionaryDatabase.COLUMN_WORD + " COLLATE NOCASE ASC" ;

    Cursor cursor = sqLiteDatabase.query(TABLE,FIELD,
            WHERE,WHERE_ARGS,null,null,ORDER_BY );
    List<Word> wordList = new ArrayList<Word>();
    int idColumnIndex = cursor.getColumnIndex(DictionaryDatabase.COLUMN_ID);
    int wordColumnIndex = cursor.getColumnIndex(DictionaryDatabase.COLUMN_WORD);
    int meanColumnIndex = cursor.getColumnIndex(DictionaryDatabase.COLUMN_MEAN);
    int favoriteColumnIndex = cursor.getColumnIndex(DictionaryDatabase.COLUMN_FAVORITE);
    int categoryColumnIndex = cursor.getColumnIndex(DictionaryDatabase.COLUMN_CATEGORY);
    int picColumnIndex = cursor.getColumnIndex(DictionaryDatabase.COLUMN_PIC);
    int historyColumnIndex = cursor.getColumnIndex(DictionaryDatabase.COLUMN_HISTORY);
    while (cursor.moveToNext()){
        Word word = new Word(cursor.getInt(idColumnIndex),cursor.getString(wordColumnIndex), cursor.getString(meanColumnIndex), cursor.getInt(favoriteColumnIndex)==1,cursor.getBlob(picColumnIndex),cursor.getString(categoryColumnIndex),cursor.getInt(historyColumnIndex)==1);
        wordList.add(word);
    }
    return wordList;
}

我想用单词mathching过滤类别。我该怎么办? 按DictionaryDatabase.COLUMN_CATEGORY = "internet"

0 个答案:

没有答案