What I want to do is loop all the user Posts in the firebase database and show it in recycler view, now each post has a user id, for this I need to write a second query which gets me the username of the particular user's post.
here's how the json looks
what i have done uptill now is this
list = new ArrayList < > ();
newsFeedRecyclerView = (RecyclerView)
findViewById(R.id.news_feed_recyclerview);
newsFeedRecyclerView.setHasFixedSize(true);
newsFeedRecyclerView.setLayoutManager(new
LinearLayoutManager(this));
newsFeedListAdapter = new NewsFeedListAdapter(list,
images);
newsFeedRecyclerView.setAdapter(newsFeedListAdapter);
Query query = databaseReference.child("Posts");
query.addListenerForSingleValueEvent(new
ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot data: dataSnapshot.getChildren()) {
final PostsPOJO postsPOJO = data.getValue(PostsPOJO.class);
images = postsPOJO.getcontent_post();
Query userDetails = databaseReference.child("Users/" + postsPOJO.getUserID());
userDetails.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String username = dataSnapshot.child("Username").getValue(String.class);
String profilePicturePath = dataSnapshot.child("ProfilePicture").getValue(String.class);
list.add(new PostsPOJO(postsPOJO.getUserID(), profilePicturePath, username, postsPOJO.getTimestamp(), postsPOJO.getPostText(), postsPOJO.getLocation(), postsPOJO.getcontent_post()));
newsFeedListAdapter.notifyDataSetChanged();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
but the problem here is that it shows all post first whose userid comes first, given the user of second post is different. for e.g( if userid 1 = john and userid 2 = alex, it show all the post of john first and then shows alex's post.
can someone help?
thank you.