我正在创建一个笔记应用程序,该应用程序可以与其他用户共享笔记。我想为用户可以访问的列表(使用uid)创建一个回收站适配器。
我需要获取所有孩子的表单列表,其中该孩子在“ shares”孩子中具有特定的uid。 有办法做到这一点的查询吗?如果没有,我怎么能做到这一点?
例如,我想获取“ shares”子项中uid =“ Cr9XLDfDMdhijkFcUAiajupXj4MDD3”的所有列表。
数据库:
{
"Lists" : {
"random-list-id-1" : {
"owner-uid" : "6r9XLDfDMdhijkFcUAiashJDSDm",
"shares" : {
"random-share-id-1" : {
"uid" : "Cr9XLDfDMdhijkFcUAiajupXj4MDD3"
},
"random-share-id-2" : {
"uid" : "Vr9XLDfDMdhijkFdsdUAiajupXj4M3"
}
}
}
}
}
代码
private void showLists() {
// This does not work
Query query = fListDatabase.orderByChild("uid").equalTo("Cr9XLDfDMdhijkFcUAiajupXj4MDD3");
// This shows all nodes
//Query query = fListDatabase.orderByPriority();
FirebaseRecyclerOptions<ListModel> options = new FirebaseRecyclerOptions.Builder<ListModel>()
.setQuery(query, ListModel.class)
.setLifecycleOwner(this)
.build();
firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<ListModel, ListViewHolder>(options) {
@Override
public ListViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new ListViewHolder(LayoutInflater.from(parent.getContext())
.inflate(R.layout.single_list_layout, parent, false));
}
@Override
protected void onBindViewHolder(final ListViewHolder viewHolder, int position, ListModel model) {
final String listId = getRef(position).getKey();
fListDatabase.child(listId).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(final DataSnapshot dataSnapshot) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
Toast.makeText(MainActivity.this, "ERROR: " + databaseError.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
};
ListsList.setAdapter(firebaseRecyclerAdapter);
}