我有这个内容解析器查询,转换为select * from book where favflag = 1
。
但现在我想更改它以便转换为select * from book where favflag = 1 AND bookid = 2;
我如何实现这一目标?
以下是内容解析程序查询:
Cursor BookCursor = getActivity().getContentResolver().query(
BookContract.BookEntry.CONTENT_URI,
null,
BookContract.BookEntry.COLUMNFAVFLAG + " = ?",
new String[]{"1"},
null);
答案 0 :(得分:3)
由于我知道Android SDK中没有BookContract
,我认为这是你自己的类。在这种情况下,我们不知道该类的API。
考虑到这一点,请尝试:
Cursor BookCursor = getActivity().getContentResolver().query(
BookContract.BookEntry.CONTENT_URI,
null,
BookContract.BookEntry.COLUMNFAVFLAG + " = ? AND "+BookContract.BookEntry.COLUMNID + " = ?",
new String[]{"1", "2"},
null);
替换BookContract.BookEntry.COLUMNID
的正确值。
答案 1 :(得分:1)
试试这个
Cursor BookCursor = getActivity().getContentResolver().query(
BookContract.BookEntry.CONTENT_URI,
null,
BookContract.BookEntry.COLUMNFAVFLAG + " = ? AND "+BookContract.BookEntry.COLUMNBOOKID + " = ?", // Use your variable here in place of COLUMNBOOKID
new String[]{"1", "2"},
null);