1

How can I display the category between (example)(3 and 7) in firebase ?

foodList.orderByChild("menuId").startAt(3).endAt(7).equalTo(categoryID)

this is my code :

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);
}

error message :

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) 
  • 1
    What is the current behaviour with the above code? – Dean Coakley Nov 14 '18 at 00:34
  • @Deancoakley : Exception :D –  Nov 14 '18 at 01:06
  • 1
    Can you attach your firebase structure. It's difficult to tell what's happening without that. And also, post what exception are you getting. – PradyumanDixit Nov 14 '18 at 03:53
  • 1
    @IbrahimHJabaly Keep in mind that Stack Overflow is an incredibly inefficient interactive debugger. If you get an exception, copy/paste the exact error message and stack trace into your question, so that we can see what you're getting. – Frank van Puffelen Nov 14 '18 at 04:34
  • Eng @FrankvanPuffelen : Done , I putted the error message . –  Nov 14 '18 at 11:25

1 Answers1

1

As the error says:

java.lang.IllegalArgumentException: Can't call equalTo() and startAt() combined

You cannot use both methods equalTo() and startAt() in a single call. If you want to sort your records according to multiple propeties, please take a look at my answer from this post, where I have explained how you can achieve this using a a combined property.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193