如何在firebase中的(示例)(3和7)之间显示类别?
foodList.orderByChild("menuId").startAt(3).endAt(7).equalTo(categoryID)
这是我的代码:
private void loadListFood(String categoryID) {
adapter = new FirebaseRecyclerAdapter<Food, FoodViewHolder>(Food.class,R.layout.food_item,FoodViewHolder.class,
foodList.orderByChild("menuId").startAt(3).endAt(7).equalTo(categoryID)
) {
@Override
protected void populateViewHolder(FoodViewHolder viewHolder, Food model, int position) {
viewHolder.food_name.setText(model.getName());
viewHolder.food_time.setText(model.getPrice());
Picasso.with(getBaseContext()).load(model.getImage()).into(viewHolder.food_image);
mDialog.dismiss();
final Food local = model ;
viewHolder.setItemClickListener(new ItemClickListener() {
@Override
public void onClick(View view, int position, boolean isLongClick) {
Intent intent = new Intent(FoodList.this,FoodDetail.class);
intent.putExtra("FoodId",adapter.getRef(position).getKey());
startActivity(intent);
}
});
}
};
recyclerView.setAdapter(adapter);
}
错误消息:
11-14 13:19:34.636 8233-8233/com.pro.ijdev.proapp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.pro.ijdev.proapp, PID: 8233
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pro.ijdev.proapp/com.pro.ijdev.proapp.FoodList}: java.lang.IllegalArgumentException: Can't call equalTo() and startAt() combined
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2778)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.IllegalArgumentException: Can't call equalTo() and startAt() combined
at com.google.firebase.database.Query.zze(Unknown Source:12)
at com.google.firebase.database.Query.equalTo(Unknown Source:0)
at com.pro.ijdev.proapp.FoodList.loadListFood(FoodList.java:63)
at com.pro.ijdev.proapp.FoodList.onCreate(FoodList.java:53)
at android.app.Activity.performCreate(Activity.java:7009)
at android.app.Activity.performCreate(Activity.java:7000)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2731)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2856)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1589)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
答案 0 :(得分:1)
错误提示:
java.lang.IllegalArgumentException:无法同时调用equalTo()和startAt()
您不能在单个调用中同时使用方法equalTo()
和startAt()
。如果您想根据多种属性对记录进行排序,请查看我在此 post 中的回答,在此我已经解释了如何使用组合属性来实现此目的。>