mercredi 25 novembre 2015

How to filter CursorAdapter with utf-8 encoding?

I have tryed this:

    @Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    if (id == POPULATE_SEARCH_ITEMS_LIST_VIEW_LOADER) {
        String whereClause = null;
        if (args != null) {
            String queryString = args.getString(ARGUMENT_QUERY_STRING);

            whereClause = MenuContract.MenuItemEntry.TABLE_NAME + "." + MenuContract.MenuItemEntry.COLUMN_NAME + " LIKE '%" + queryString + "%'";
        }

        // load menu items and their values to populate list view
        return new CursorLoader(getContext(),
                MenuContract.MenuItemEntry.buildMenuItemsWithMenuItemValues(),
                MENU_ITEMS_COLUMNS,
                whereClause,
                null,
                MenuContract.MenuItemEntry.TABLE_NAME + "." + MenuContract.MenuItemEntry.COLUMN_NAME + " COLLATE LOCALIZED ASC"
        );
    }
    return null;
}

Here I used " LIKE '%" + queryString + "%'" to filter, but I can't filter Russian words, because they are't ASCII, they UTF-8 encoding.

I can't do this because of known sqlite bug:

(A bug: SQLite only understands upper/lower case for ASCII characters by default. The LIKE operator is case sensitive by default for unicode characters that are beyond the ASCII range. For example, the expression 'a' LIKE 'A' is TRUE but 'æ' LIKE 'Æ' is FALSE.)

From docs: http://ift.tt/12fA5tR

So, the question is: How to filter CursorAdapter with UTF-8 encoding?

Aucun commentaire:

Enregistrer un commentaire