有没有办法从传递给 FireBasUI RecyclerAdapter 的持有者类布局中删除视图?



看,这是我的问题:我使用了这个FireBaseRecyclerViewAdapter,所以我可以在我的Homefragment中上传和显示我的帖子。但问题来了:我有一个布局,上面显示图片 a 和文本。但是我希望能够显示没有图像的帖子,所以我为每个帖子声明了一个变量,称为posttype,如果posttype为0,它是一个文本帖子,否则它是一个图像帖子。问题是我怎样才能从支架上完全删除图像视图?

我试过:

if(holder.textViewpostType.getText().equals("0")){
holder.ImageViewpicture.setImageDrawable(null);
}

但问题是 ImageView 仍然停留在那里,只是看不见,但我希望它完全消失你知道吗?

这是整个PostsAdapter类的代码,快速回答将非常有帮助:

package com.LiFit;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.firebase.ui.firestore.FirestoreRecyclerAdapter;
import com.firebase.ui.firestore.FirestoreRecyclerOptions;
import com.squareup.picasso.Picasso;
import de.hdodenhof.circleimageview.CircleImageView;
public class PostsAdapter extends FirestoreRecyclerAdapter<Posts, PostsAdapter.PostsHolder> {
public PostsAdapter(@NonNull FirestoreRecyclerOptions<Posts> options) {
super(options);
}
@Override
protected void onBindViewHolder(@NonNull PostsHolder holder, int position, @NonNull Posts model) {
holder.textViewdescription.setText(model.getDescription());
holder.textViewpostType.setText(String.valueOf(model.getPostType()));
holder.textViewtime.setText("uploaded at "+model.getTime());
holder.textViewuid.setText(model.getUid());
holder.textViewusername.setText(model.getUsername());
holder.buttonlikes.setText("Likes: "+model.getLikes());
Picasso.get().load(model.getProfileImage()).into(holder.circleImageViewprofileImage);
Picasso.get().load(model.getPicture()).into(holder.ImageViewpicture);
holder.textViewuid.setVisibility(View.INVISIBLE);
holder.textViewpostType.setVisibility(View.INVISIBLE);
if(holder.textViewpostType.getText().equals("0")){
holder.ImageViewpicture.setImageDrawable(null);
}
}
@NonNull
@Override
public PostsHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.posts_layout, parent, false);
return new PostsHolder(v);
}
class PostsHolder extends RecyclerView.ViewHolder {
TextView textViewdescription, textViewpostType, textViewtime, textViewuid, textViewusername;
Button buttonlikes;
ImageView ImageViewpicture;
CircleImageView circleImageViewprofileImage;
public PostsHolder(@NonNull View itemView) {
super(itemView);
textViewdescription = itemView.findViewById(R.id.post_description);
textViewpostType = itemView.findViewById(R.id.post_postType);
textViewtime = itemView.findViewById(R.id.post_uploadTime);
textViewuid = itemView.findViewById(R.id.post_userUID);
textViewusername = itemView.findViewById(R.id.post_userName);
buttonlikes = itemView.findViewById(R.id.post_likes);
ImageViewpicture = itemView.findViewById(R.id.post_image);
circleImageViewprofileImage = itemView.findViewById(R.id.post_profileImage);
}
}
}

兄弟,我太笨了

如果您想知道,请这样做: 持有。ImageViewpicture.setVisibility(View.GONE(;

相关内容

  • 没有找到相关文章

最新更新