0

I am trying to implement a Like/Unlike system on a post. I want a red star to be displayed where the username is "abcd" else a white star would be displayed. The interface is:

interface onStarClicked{
    void isClicked(String name);
}

The bind function in the viewholder is:

public void bind(Post post, onStarClicked starClicked){


        //Log.d("NAME", post.getName());

        String usrnm = post.getName();
        starClicked.isClicked(usrnm);

        name.setText(post.getName());
        posttext.setText(post.getPost());
        starCount.setText(String.valueOf(post.getHearts()));

    }

Post is the model for post present in database. The onBindViewHolder is:

@Override
    protected void onBindViewHolder(@NonNull final PostViewHolder holder, int position, @NonNull Post model) {


        final ImageView img = holder.itemView.findViewById(R.id.star_click);

        holder.bind(model, new onStarClicked() {
            @Override
            public void isClicked(String name) {


                if(name == "abcd"){
                    Glide.with(holder.itemView.getContext())
                            .load(R.drawable.red_star)
                            .into(img);
                }else{
                    Glide.with(holder.itemView.getContext())
                            .load(R.drawable.white_star)
                            .into(img);
                }
            }




        });

    }

Still the imageview shows white star for every post. How to solve this issue?

1 Answers1

2

Its a string u should do:

if(name.equals("abcd"){
  //do your thing
}
Jason
  • 444
  • 4
  • 6