0

I am building a social app using firebase , when it comes to profile activity and I want to post only person's post I can't ,I managed to post all users post to the home page as news feed but I can't filter only users posts , this is the users node with the person id as a child

i tried this

   userRef=FirebaseDatabase.getInstance().getReference().child("Users");
RecieverId=getIntent().getExtras().get("brand_id").toString();

 private void DisplayAllOffers() {
        FirebaseRecyclerOptions<Posts> options = new FirebaseRecyclerOptions.Builder<Posts>()
                .setQuery(PostRef.child(RecieverId),Posts.class).build();

        FirebaseRecyclerAdapter<Posts,PostViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Posts, PostViewHolder>(options) {
            @Override
            protected void onBindViewHolder(@NonNull  PostViewHolder holder, int position, @NonNull Posts model) {
//                holder.Title.setText(model.getTitle());
                final  String postKey = getRef(position).getKey();
                holder.Price.setText(model.getPrice());
                holder.Duration.setText(model.getDuration());
                holder.date.setText(model.getDate());
                holder.description.setText(model.getDescription());
                holder.time.setText(model.getTime());
                holder.username.setText(model.getUsername());
                holder.setLikeButtonStatus(postKey);
                Picasso.get().load(model.getProfileImage()).into(holder.ProfileImage);
                Picasso.get().load(model.getPostImage()).into(holder.postImage);

                holder.itemView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent postIntent = new Intent(BrandActivity.this,ClickPostActivity.class);
                        postIntent.putExtra("postKey",postKey);
                        startActivity(postIntent);
                    }
                });









            }

            @NonNull
            @Override
            public PostViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {

                View view =LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.offer_layout,viewGroup,false);
                PostViewHolder holder =new PostViewHolder(view);
                return holder;

            }
        };
        Profile_posts.setAdapter(firebaseRecyclerAdapter);
        firebaseRecyclerAdapter.startListening();


    }

and it returns an empty recyclerview

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Have you called adapter's startListening() method Check this [answer](https://stackoverflow.com/a/47228433/9263083) – sanoJ May 20 '19 at 06:35

1 Answers1

0

If you want to user-specific post than you have to change your options with

FirebaseRecyclerOptions<Posts> options = new FirebaseRecyclerOptions.Builder<Posts>().setQuery(PostRef.orderByChild("Uid").equalTo(FirebaseAuth.getInstance().getUid())),Posts.class).build();

here this PostRef.orderByChild("Uid").equalTo(FirebaseAuth.getInstance().getUid()) query filter curent user post

you also can get other than the current user specific post, all you have to do only change FirebaseAuth.getInstance().getUid() to user id in equalTo function