0

SQLliteQueryBuilderクエリに複数の選択(where句)を追加するにはどうすればよいですか?たとえば、(10〜20歳AND身長= 60)OR(性別='F')

public Cursor query (SQLiteDatabase db, String[] projectionIn, String selection, String[] selectionArgs, String groupBy, String having, String sortOrder)

selection   A filter declaring which rows to return, formatted as an SQL WHERE clause (excluding the WHERE itself). Passing null will return all rows for the given URL.
selectionArgs   You may include ?s in selection, which will be replaced by the values from selectionArgs, in order that they appear in the selection. The values will be bound as Strings.
4

1 に答える 1

10

基本的に、selection文字列で条件を渡します。次のように言及します

String selection = "arg1 = ? and arg2 = ?" ...

およびselectionArgsis String 配列であるため、選択値は次のようになります。

selectionArgs[0] = "value of arg1";
selectionArgs[1] = "value of arg2";

and so on

したがって、次を使用できます。

String selection = "Age between ? and ? and Height = ?";
selectionArgs[0] = "10";
selectionArgs[1] = "20";
selectionArgs[2] = "168";

そして、これらの文字列を に渡しますquery

お役に立てれば!

于 2012-05-20T19:38:22.013 に答える