Skip to content
Advertisement

How to show Posts by Specific users in a recyclerview using FirebaseUI library (Java Android)

I am using FirebaseUI library for my social app. I was able to retrieve posts by all users into a recyclerview. My goal is to have another option where users can view and edit their own posts. I cant seem to get user specific posts from the database, how do I go about doing this? Also I’m using a recyclerview within a Fragment

Database Structure

Database structure here

PostAdapter

JavaScript

How I retrieve all posts

JavaScript

Expected Outcome screenshot

Home where users see all posts

Where users view their own posts

Advertisement

Answer

The relevant code is:

JavaScript

Since you’re always passing base to the adapter, it will always show all child nodes of UserPosts. To only show the child nodes for a specific user, you can use a query:

JavaScript
Advertisement