如何在url为空时隐藏imageview

avkwfej4  于 2021-07-06  发布在  Java
关注(0)|答案(1)|浏览(348)

我有一个图像查看其加载图片从firebase数据库的网址与毕加索图像加载器。我希望在firebase数据库url为空时隐藏imageview。如何设置imageview setvisibility在那个时候就消失了。
我的密码是

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);

    }
}
xqkwcwgp

xqkwcwgp1#

setVisibility() 每项功能 View 在android中。你可以找到这个,如果你谷歌在正确的方式。
请参阅下面的代码以解决您的问题。

if (trollModel.getImage().isEmpty()) {
   trollViewHolder.thrillersimage.setVisibility(View.GONE);
} else {
   trollViewHolder.thrillersimage.setVisibility(View.VISIBLE);
   Picasso.get().load(trollModel.getImage())
                        .into(trollViewHolder.thrillersimage);
}

相关问题