简体   繁体   中英

Android - Custom ListView with internet images. Can't download images

I'm trying to display a custom ListView that has a thumbnail image and text in each row.

I have the text stored in one ArrayList<String> and the URLs to each thumbnail stored in another one.

I can get the text to appear in the list, but I can only statically/manually set the image.

My question: How can I make my ImageView download the thumbnail image and display it? Each thumbnail is unique.

Here is my code for populating the ListAdapter:

class CustomAdapter extends ArrayAdapter<String> 
{
    CustomAdapter() 
    {
        super(MyClass.this, R.layout.listrows, R.id.txtAddress,propertyAddress);
    }

    public View getView(int position, View convertView, ViewGroup parent)
    {
        View row=super.getView(position, convertView, parent);
        ViewHolder holder=(ViewHolder)row.getTag();

        if (holder==null) 
        {                         
            holder=new ViewHolder(row);
            row.setTag(holder);
        }

        //I tried this,
        holder.icon.setImageURI(Uri.parse(imageList.get(position).toString()));
        //But I get a NullPointer

        return(row);
    }
}

Also, my ViewHolder class is pretty normal:

class ViewHolder
{
    ImageView icon=null;
    ViewHolder(View base)   {
        this.icon=(ImageView)base.findViewById(R.drawable.ic_launcher);
    }
}

I would appreciate any help with this.

Thanks!

setImageUri is to set a local position. not for the internet.

try to use ImageDownloader .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM