美文网首页
CursorLoader配置参数和模糊查询

CursorLoader配置参数和模糊查询

作者: 美晨菌 | 来源:发表于2020-09-03 14:21 被阅读0次
    1. 配置loader
        public void configureLoader(CursorLoader loader) {
            String query = getQueryString();
            if (query == null) query = "";
            query = query.trim();
    
            loader.setUri(Provider.CONTENT_URI);
            if (isSearchMode() && !TextUtils.isEmpty(query)) {
                loader.setProjection(getProjection(true));
                loader.setSelection(
                        Provider.SUBSCRIBED + "= 1 AND (" +
                                Provider.SERVICE_NAME + " LIKE '%" + query + "%' OR " +
                                Provider.EMAIL + " LIKE '%" + query + "%' OR " +
                                Provider.PHONE_NUMBER + " LIKE '%" + query + "%')");
                loader.setSelectionArgs(null);
                loader.setSortOrder(Provider.SUBSCRIBED + "," + Provider.SERVICE_NAME);
                if (loader instanceof DefaultsLoader) {
                    ((DefaultsLoader) loader).setLoadPreset(false);
                }
            } else {
                loader.setProjection(getProjection(false));
                loader.setSelection(Provider.SUBSCRIBED + "= 1");
                loader.setSelectionArgs(null);
                loader.setSortOrder(Provider.SUBSCRIBED + "," + Provider.SERVICE_NAME);
                if (loader instanceof DefaultsLoader) {
                    ((DefaultsLoader) loader).setLoadPreset(false);
                }
            }
    

    相关文章

      网友评论

          本文标题:CursorLoader配置参数和模糊查询

          本文链接:https://www.haomeiwen.com/subject/zkcgsktx.html