This is a question when you get an image from url using picasso.

Asked 1 years ago, Updated 1 years ago, 71 views

I am currently using recyclerview and receiving images from url using picaso. Json parsing is also in use.

At first, I receive 30 pieces of data and spray them on recyclerview, and when the scroll touches the floor, I receive 30 pieces of data and show them. However, if there is no Clan in the middle, the Clan name and Clanmark (image from url) should just be expressed as blank, but it doesn't work. ㅜ <

@Override
public void onBindViewHolder(RankingRecyclerItemViewHolder holder, int position) {
    RankingRecyclerViewItem item = RankingRecyclerViewItemList.get(position);

    holder.sunwiTxv.setText(item.sunwi);
    Picasso.with(context).load(item.getUrl_image()).resize(40, 40).into(holder.clanImage);
    holder.ladderTxv.setText(item.ladder);
    holder.winrateTxv.setText(item.winrate);
    holder.clanTxv.setText(item.clan);
    holder.idTxv.setText(item.name);

}

This is part of the contents of Recycler View Adapter

                String clan = childJsonObject.getString("clan");

                if (clan == null) {
                    RankingRecyclerViewItem.clan = null;
                    RankingRecyclerViewItem.url_image = null;
                } } else {
                    RankingRecyclerViewItem.clan = childJsonObject.getString("clan");

This is when you use it on the main.

How do I use coding? Url does not exist if there is no image. How can I show it as blank when there is no image? ㅜ<

android json recyclerview picasso

2022-09-22 14:49

1 Answers

If you want to show a blank screen when the image does not exist, use the onBindViewHolder() function to make holder.clanImage Visible and Visible.

if (item.getUrl_image() != null) {
    holder.clanImage.setVisibility(View.VISIBLE);
    Picasso.with(context).load(item.getUrl_image()).resize(40, 40).into(holder.clanImage);    
} } else {
    holder.clanImage.setVisibility(View.INVISIBLE);
}


2022-09-22 14:49

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.