android - FilterQueryProvider not working -


i using following snippet:

filterqueryprovider provider = new filterqueryprovider() {                     @override                     public cursor runquery(charsequence constraint) {                        /* uri uri = textutils.isempty(constraint) ? employeecontentprovider.uri_employees :                                 uri.withappendedpath(employeecontentprovider.uri_employees, constraint.tostring()); */                         return getcontentresolver().query( employeecontentprovider.uri_employees, employee.fields, employee.col_name + " ?", new string[]{constraint.tostring()}, null);                      }                 }; 

in above if use uri.withappendedpath , supply _id field search constriant, works fine. want search based on name. here not working. content provider follows:

@override     public cursor query(uri uri, string[] projection, string selection, string[] selectionargs, string sortorder) {          cursor result = null;         system.out.println("selection: " + selection);         system.out.println("selection args: " + arrays.tostring(selectionargs));          if (uri_employees.equals(uri)) {             result = databasehandler                     .getinstance(getcontext())                     .getreadabledatabase()                     .query(employee.table_name, employee.fields, selection, selectionargs, null, null, employee.col_name, null);              result.setnotificationuri(getcontext().getcontentresolver(), uri_employees);         } else if (uri.tostring().startswith(employee_base)) {              final long id = long.parselong(uri.getlastpathsegment());             result = databasehandler                     .getinstance(getcontext())                     .getreadabledatabase()                     .query(employee.table_name, employee.fields,                             employee.col_id + " ?",                             new string[]{string.valueof(id)}, null, null,                             null, null);             result.setnotificationuri(getcontext().getcontentresolver(), uri_employees);         } else {             throw new unsupportedoperationexception("not yet implemented");         }          return result;     } 

what miss here?

so here solution, interesting here how , takes precedence on or

        public void onloadfinished(loader<cursor> loader, cursor mcur) {               filterqueryprovider provider = new filterqueryprovider() {                 @override                 public cursor runquery(charsequence constraint) {                     uri uri = textutils.isempty(constraint) ? employeecontentprovider.uri_employees :                             uri.withappendedpath(employeecontentprovider.uri_employees, constraint.tostring());                      string = employee.col_department + " ?" + " , (" + employee.col_name + " ? or " + employee.col_empid + " ? )";                     string selectionargs[] = new string[]{string.valueof(department), string.valueof("%" + constraint + "%"), string.valueof("%" + constraint + "%")};                     return getcontentresolver().query(uri, employee.fields, where, selectionargs, null);                  }             };              adapter1 = new cursoradapter(listactivity.this, r.layout.details_list_row, mcur);             adapter1.setfilterqueryprovider(provider);             mrecyclerview.setadapter(adapter1);          } 

Comments

Popular posts from this blog

r - how do you merge two data frames the best way? -

How to debug "expected android.widget.TextView but found java.lang.string" in Android? -

php - mySQL problems with this code? -