我正在尝试根据用户存储的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个共享首选项(截至目前,忽略程序包字段)-
这是FIrebase中数据库的屏幕截图-
请指导如何根据2个共享首选项进行此排序/过滤。活动开始时值多少?