How to show images in imageview in simple adapter?

孤街浪徒 提交于 2019-11-30 20:59:22

problem solved,the URL coming from the image had "& amp;" inside it which was not understood.

Nowadays you can use Picasso instead of writing your own custom image loader. Otherwise, your code helped a ton. Thanks bro.

Heres my adapter using your code with Picasso.

public class CustomList extends SimpleAdapter {

private Context mContext;
public LayoutInflater inflater=null;
public CustomList(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to) {
    super(context, data, resource, from, to);
    mContext = context;
    inflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View vi=convertView;
    if(convertView==null)
        vi = inflater.inflate(R.layout.list_view_row, null);

    HashMap<String, Object> data = (HashMap<String, Object>) getItem(position);
    TextView text = (TextView)vi.findViewById(R.id.name);
    String name = (String) data.get("name");
    text.setText(name);
    ImageView image=(ImageView)vi.findViewById(R.id.img);
    String image_url = (String) data.get("image_url");
    Picasso.with(mContext).load(image_url).into(image);
    return vi;
  }
}
Eyali

The solution with Picasso works great, just remember to change the parameters you are sending in the 'puts' of the original class!

In order to import Picasso add it to the dependencies as

compile group:'com.squareup.picasso', name:'picasso', version:'2.5.2'

In build.gradle (app) Then View-->Tools Windows --> Gradle and then press the refresh button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!