简体   繁体   中英

List View Adapter with url image

Hello I have one List view example with image in drawable folder...but i need get image Foto from url how to change drawable to string url to work fine.

i'm newbie in android,sorry.

public class list_view_comments {

    protected Drawable foto;
    protected String nombre;
    protected String cargo;
    protected long id;

    public list_view_comments(Drawable foto, String nombre, String cargo) {
        super();
        this.foto = foto;
        this.nombre = nombre;
        this.cargo = cargo;
    }

    public list_view_comments(Drawable foto, String nombre, String cargo, long id) {
        super();
        this.foto = foto;
        this.nombre = nombre;
        this.cargo = cargo;
        this.id = id;
    }

    public Drawable getFoto() {
        return foto;
    }

    public void setFoto(Drawable foto) {
        this.foto = foto;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    public String getCargo() {
        return cargo;
    }

    public void setCargo(String cargo) {
        this.cargo = cargo;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }
}

我使用库查询来解决这个问题https://code.google.com/p/android-query/

Drawables dont have URIs. however u can parse them and this is how u do it:

Uri uri = Uri.parse("android.resource://your.package.here/drawable/image_name");

Directly specifying web url on android view is not possible. You have to download the image from url, store it in some location and then use it in the Imageview

File image = new  File(storedPath);

if(image.exists()){
  Bitmap myBitmap = BitmapFactory.decodeFile(image.getAbsolutePath());
  ImageView myImage = (ImageView) findViewById(R.id.imageview_xyz);
  myImage.setImageBitmap(myBitmap);
}

downloading should be done asynchronously when using listview for list view scroll to be smooth. Final output you need to target is like, user keep scrolling the list, images slowly appear as and when downloading is completed. Lot of other optimization technics guide-lined by android should be used to get the best performance(convertViews, viewHolder etc)

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