Reputation: 345
I am using FirebaseRecyclerAdapter and I am trying to show the post for following users only so I couldn't get the correct query for that the query that I need is at the pic describe:
I am currently using this method:
mDatabase= FirebaseDatabase.getInstance().getReference().child("Posts");
FirebaseRecyclerAdapter<Getting_Posts, PostViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Getting_Posts, PostViewHolder>(
Getting_Posts.class, R.layout.post_card_design, PostViewHolder.class, mDatabase) {
@Override
protected void populateViewHolder(final PostViewHolder viewHolder, final Getting_Posts model, int position) {
final String Post_Key = getRef(position).getKey();
}
};mPostList.setAdapter(firebaseRecyclerAdapter);
};
this method shows all post but I need to show post for following user
So I need the query that must I use it so please any help.
Upvotes: 1
Views: 1087
Reputation: 1238
I also developed an app little bit similar to Instagram and used the conditions which you are looking for, So first of all fetch all your followings from firebase into an ArrayList.And than make conditions fetching posts as
if(followeinglist.contains(UID FROM POST)){mArrayListPost.add(YOUR POST);}
and find followings as
DatabaseReference userPostRef = mDatabase.child(KeyTAG.TAG_FOLLOWINGS).child(YOUR USER ID).orderByChild("userid");
if (userPostRef == null) {
} else {
userPostRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Iterable<DataSnapshot> children = dataSnapshot.getChildren();
for (DataSnapshot child : children) {
followeinglist.add(child.getKey());
}
mAdapter1.notifyDataSetChanged();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
Upvotes: 0
Reputation: 201
Try this:
mDatabase= FirebaseDatabase.getInstance().getReference().child("Posts").orderByChild("UID").equalTo("UID TO SEARCH FOR");
FirebaseRecyclerAdapter<Getting_Posts, PostViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Getting_Posts, PostViewHolder>(
Getting_Posts.class, R.layout.post_card_design, PostViewHolder.class, mDatabase)
Upvotes: 2