I have an Activity, which holds a TabHolder. Every tab its a Fragment.
One of the tabs, has a ListView, which should be fulfilled with photos, and text. The problem is, when I tap in the tab, the UI takes a while to load, because I have to get the photos by the URI, resize the bitmap to an ImageView in the adapter in the ListView, and present it. I would like to put the loading of the photos in a thread, and present a ProgressDialog to the user, while the photographs loads. But I don't know where! If I do it in getView method in the adapter, it starts to behave strangely, because it is called as many times as photos in the array...tried doing this in OnCreateView(), inside the Fragment:
adapter=new FotoAdapter(getActivity(), arrayFotos);
final ProgressDialog dialog=ProgressDialog.show(getActivity(), getString(R.string.onemoment), getString(R.string.fotoloading));
handler=new Handler(){
@Override
public void handleMessage(Message msg) {
if(msg.what==1){
dialog.dismiss();
}
}
};
Thread thread=new Thread(new Runnable() {
@Override
public void run() {
listaFotos.setAdapter(adapter);
Message message=new Message();
message.what=1;
handler.sendMessage(message);
}
});
thread.start();
...but it does nothing, no dialog is shown, and takes the same time to present the UI to the user.
How could I achieve it?
Thank you.
EDIT:
After suggestion, tried Picasso. Here you can see both approaches, with Picasso and without it:
String path=fotos.get(position).getFotoPath();
//Picasso.with(c).load(path).resize(80, 80).into(holder.foto);
Bitmap foto= BitmapFactory.decodeFile(path);
int bmWidth=foto.getHeight();
int bmHeight=foto.getHeight();
int ivWidth;
int ivHeigth;
int new_width;
int new_height;
ivWidth=dpToPx(80);
new_width=ivWidth;
new_height = (int) Math.floor((double) bmHeight *( (double) new_width / (double) bmWidth));
Bitmap newbitMap = Bitmap.createScaledBitmap(foto, new_width, new_height, true);
holder.lat.setText(fotos.get(position).getLatitud().toString());
holder.lon.setText(fotos.get(position).getLongitud().toString());
holder.foto.setImageBitmap(newbitMap);
Using Picasso, I cannot see the image in the ImageView.