英文:
How to Imageview hide when url is empty
问题
private void LoadData(String categoryId) {
options = new FirebaseRecyclerOptions.Builder<TrollModel>()
.setQuery(MCC, TrollModel.class)
.build();
adapter = new FirebaseRecyclerAdapter<TrollModel, TrollViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull TrollViewHolder trollViewHolder, int i, @NonNull TrollModel trollModel) {
trollViewHolder.thrillername.setText(trollModel.getTitle());
if (trollModel.getImage() != null && !trollModel.getImage().isEmpty()) {
trollViewHolder.thrillersimage.setVisibility(View.VISIBLE);
Picasso.get().load(trollModel.getImage()).into(trollViewHolder.thrillersimage);
} else {
trollViewHolder.thrillersimage.setVisibility(View.GONE);
}
trollViewHolder.setItemClickListner(new ItemClickListner() {
@Override
public void onClick(View view, int position, boolean isLongClick) {
Intent detailsIntent = new Intent(TrollActivity.this, TrollDetailActivity.class);
detailsIntent.putExtra("CategoryId", adapter.getRef(position).getKey());
startActivity(detailsIntent);
}
});
}
@NonNull
@Override
public TrollViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.troll_items, parent, false);
return new TrollViewHolder(v);
}
};
adapter.startListening();
recyclerView.setAdapter(adapter);
}
英文:
I have a Imageview its load image from Firebase Database url with Picasso Image loader. I wish to hide imageview when firebase database url is empty. How to set Imageview setVisibility gone in that time.
My code is
LoadData(categoryId);
}
private void LoadData(String categoryId) {
options = new FirebaseRecyclerOptions.Builder<TrollModel>().setQuery(MCC,TrollModel.class).build();
adapter = new FirebaseRecyclerAdapter<TrollModel, TrollViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull TrollViewHolder trollViewHolder, int i, @NonNull TrollModel trollModel) {
trollViewHolder.thrillername.setText(trollModel.getTitle());
Picasso.get().load(trollModel.getImage())
.into(trollViewHolder.thrillersimage);
trollViewHolder.setItemClickListner(new ItemClickListner() {
@Override
public void onClick(View view, int position, boolean isLongClick) {
Intent detailsIntent = new Intent(TrollActivity.this, TrollDetailActivity.class);
detailsIntent.putExtra("CategoryId", adapter.getRef(position).getKey());
startActivity(detailsIntent);
}
});
}
@NonNull
@Override
public TrollViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.troll_items, parent, false);
return new TrollViewHolder(v);
}
};
adapter.startListening();
recyclerView.setAdapter(adapter);
}
}
答案1
得分: 1
在安卓中,每个视图(View)都有一个setVisibility()
函数。如果你以正确的方式在谷歌上搜索,你可以找到这个函数。
请参考下面的代码来解决你的问题:
if (trollModel.getImage().isEmpty()) {
trollViewHolder.thrillersimage.setVisibility(View.GONE);
} else {
trollViewHolder.thrillersimage.setVisibility(View.VISIBLE);
Picasso.get().load(trollModel.getImage())
.into(trollViewHolder.thrillersimage);
}
英文:
There is setVisibility()
funciton for every View
in android. You can find this if you google it in right way.
Refer below code to solve your problem.
if (trollModel.getImage().isEmpty()) {
trollViewHolder.thrillersimage.setVisibility(View.GONE);
} else {
trollViewHolder.thrillersimage.setVisibility(View.VISIBLE);
Picasso.get().load(trollModel.getImage())
.into(trollViewHolder.thrillersimage);
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论