以下是我的代码,它试图根据3个参数进行查询。但是以下查询适用于OR逻辑函数。有没有人知道AND逻辑功能如何。我按照文档中的说明尝试正常列出它们,但它总是返回一个空列表。
public class ResterauntList1 extends Activity {
String rValue, cValue, lValue;
ArrayAdapter<String> adapter;
ProgressDialog mProgressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_resteraunt_list1);
rValue = getIntent().getStringExtra("restrauntName");
cValue = getIntent().getStringExtra("restrauntCuisine");
lValue = getIntent().getStringExtra("restrauntLocation");
populateList(rValue, cValue, lValue);
}
private void populateList(final String rValue, final String cValue,
final String lValue) {
ParseQueryAdapter.QueryFactory<ParseObject> factory = new ParseQueryAdapter.QueryFactory<ParseObject>() {
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public ParseQuery create() {
ParseQuery<ParseObject> query = new ParseQuery("resdb");
query.whereEqualTo("name", rValue);
query.whereEqualTo("cuisine", cValue);
query.whereEqualTo("area", lValue);
return query;
}
};
ParseQueryAdapter<ParseObject> adapter = new ParseQueryAdapter<ParseObject>(
this, factory);
adapter.setTextKey("name");
adapter.addOnQueryLoadListener(new OnQueryLoadListener<ParseObject>() {
@Override
public void onLoading() {
mProgressDialog = new ProgressDialog(ResterauntList1.this);
mProgressDialog
.setTitle("Searching for Restaurants matching your search");
mProgressDialog.setMessage("Loading...");
mProgressDialog.setIndeterminate(false);
mProgressDialog.show();
}
@Override
public void onLoaded(List<ParseObject> objects, Exception e) {
mProgressDialog.dismiss();
}
});
final ListView listView = (ListView) findViewById(R.id.restListView1);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
ParseObject object = (ParseObject) listView
.getItemAtPosition(position);
String Id = object.getObjectId();
Intent i = new Intent(getApplicationContext(),
SingleRestraunt.class);
i.putExtra("restId", Id);
startActivity(i);
}
});
}
不会返回任何错误,但它总是返回一个空的列表视图。有什么建议?正如额外的OR类型查询一样。
答案 0 :(得分:0)
这应该是一个简单的解决方法。
ParseQuery<ParseObject> query = new ParseQuery("resdb");
query.whereEqualTo("name", rValue);
query.whereEqualTo("cuisine", cValue);
query.whereEqualTo("area", lValue);
这将为您提供AND功能。
希望这有帮助!