How to upload web images inside a ListView?

0

I have a json something like this (simplified the original):

[{ image:"http://site.com/imagem.png", title:"Titulo", desc: "descrição" }]

I would like to load all the content, including the image inside a ListView in the app, I tried to use HttpURLConnection within the same Thread, to get the bitmap of the image, but this causes it to take a lot to load, and I've seen in apps like youtube that first loads the content in text (lighter), and then loads the heavier the image or thumbnail, then the question is: How can I load the images in a way that does not affect the loading of the text file, and then refresh the image inside the ListView?

My class that inherits from AsyncTaskLoader<List<Dados>>

@Override
public List<Dados> loadInBackground() {
    return QueryUtils.fetchMainData(url);
}

Static method of QueryUtils :

public static List<Dados> fetchMainData(String stringUrl) {
    // TRANSFORMA STRING EM URL
    URL url = createUrl(stringUrl);
    List<Dados> list = null;
    try {
        // CONECTA NA INTERNET E RETORNA JSON CRÚ
        String json = makeHttpRequest(url);
        // PROCESSA O JSON E RETORNA A LISTA DE DADOS
        list = getImagemData(json);

    } catch (IOException e) {
        e.printStackTrace();
    }
    return list;
}

Data Class:

class Dados{

    private Bitmap image;
    private String title;
    private String description;

    Imagem(Bitmap image, String title, String description) {
        this.title = title;
        this.description = description;
        this.image = image;
    }

    String getTitle() {
        return title;
    }

    String getDescription() {
        return description;
    }

    Bitmap getImage() {
        return image;
    }

    boolean hasImage() {
        return image != null;
    }

}
    
asked by anonymous 30.08.2017 / 00:27

0 answers