0
I have a json more or less like this (simplified the original):
[{ image:"http://site.com/imagem.png", title:"Titulo", desc: "descrição" }]
I would like to upload all the content, including the image inside a ListView
in the app, I tried using the HttpURLConnection
inside the same Thread, to get the image bitmap, only it takes a long time to load, and I’ve seen in apps like youtube that first loads the content in text (lighter), and then loads the heaviest that would be 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 update the image within 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;
}
}
I recommend using the Picasso library. It handles this complexity for vc as cache, etc... http://square.github.io/picasso/ . There’s a little example that I think will solve.
– André Ozawa
You have created a custom listview for all your needs already ?
– Dev
Yes... I just need to be able to load the image independently of the text.
– Anderson Santos