Home > database >  How to hide the imageview in RecyclerView permanently through firebase realtime database
How to hide the imageview in RecyclerView permanently through firebase realtime database

Time:11-09

This is my first time with recyclerview and I need some help. I am using a firebase and I want to hide an item(imageview) from my recyclerview adapter.

public RecyclerViewHolder(View itemView, final OnItemClickListener listener) {
          super(itemView);
          image = itemView.findViewById(R.id.listrow_img1);
          title = itemView.findViewById(R.id.listrow_tv1);
          lock = itemView.findViewById(R.id.lock_accountImg);
}

I want to hide the lock image if my firebase realtime database don't have a child named("password"). if it has that child() the lock image will show up. Thank you in advance for those who help.

CodePudding user response:

To hide or display a view according to a condition, create a method inside the ViewHolder class:

public void hideDisplayImageView(boolean passwordExist) {
    if (passwordExist) {
        lock.setVisibility(View.VISIBLE);
    } else {
        lock.setVisibility(View.GONE);
    }
}

And call from within the onBindViewHolder method:

String password = list.get(position).getPassword();
if(password == null) {
    holder.hideDisplayImageView(true);
} else {
   holder.hideDisplayImageView(false);
}

CodePudding user response:

You can try this like

if("your condition for the child is true"){
 image.setVsisibility(View.VISIBLE)}
 else{
 image.setVsisibility(View.GONE)}

CodePudding user response:

Kolin

val firebaseData = list.[position].getChild()
if(!firebaseData == "password")
  holder.image.isVisible = false
else holder.image.isVisible = true

Java

String firebaseData = list.getPosition().getChild();
if(!firebaseData.contains("password")){
   holder.image.setVisibility(View.GONE)
  }else{
     holder.image.setVisibility(View.VISIBLE) 
  }
  • Related