Android中Firebase数据库参考上的多个where子句条件。如何执行此动作

时间:2018-08-04 21:42:49

标签: android firebase firebase-realtime-database sharedpreferences

我正在尝试根据用户存储的2个共享首选项值从Firebase数据库中过滤数据。

这是我需要合并更改的代码-

String fieldPref = sharedPreferences_sort.getString("field","Sales and marketing");
String locationPref = sharedPreferences_sort.getString("location","Delhi");

// Need to add the filtering code on this Database Reference
     mMessagesDatabaseReference.addChildEventListener(new ChildEventListener() {
            @Override
            public void onChildAdded(DataSnapshot dataSnapshot, String s) {
                post itemObject = dataSnapshot.getValue(post.class);
                //this is where data from database is entered into a list of objects
                postAdapterObject.add(itemObject);
                progressBar.setVisibility(View.GONE);
            }
        @Override
        public void onChildChanged(DataSnapshot dataSnapshot, String s) {

            post itemObject = dataSnapshot.getValue(post.class);
            postAdapterObject.add(itemObject);

            progressBar.setVisibility(View.GONE);

        }

        @Override
        public void onChildRemoved(DataSnapshot dataSnapshot) {

//                post itemObject = dataSnapshot.getValue(post.class);
            //postAdapterObject.add(itemObject);

        }

        @Override
        public void onChildMoved(DataSnapshot dataSnapshot, String s) {

        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });

这是Shared Filters UI的屏幕截图,其中有2个共享首选项(截至目前,忽略程序包字段)-

enter image description here

这是FIrebase中数据库的屏幕截图-

enter image description here

请指导如何根据2个共享首选项进行此排序/过滤。活动开始时值多少?

0 个答案:

没有答案