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);
}
}
网友评论