hi i have a custom listview that contain an image and textview ,am using handler inside the getview of listview of adapter for loading images , when all the images are load , and then i change the orientation of my phone the image again start to download , i want to block this one,ie when all the images are load ,and when am orientation changes it take no effect.
public View getView(final int position, View convertView, ViewGroup parent) {
final String imageurl = imageUrls.get(position);
LayoutInflater inflate = LayoutInflater.from(context);
View v = inflate.inflate(rowResId, parent, false);
final ImageView image = (ImageView) v.findViewById(R.id.image);
final ProgressBar progress = (ProgressBar) v
.findViewById(R.id.progress);
image.setVisibility(View.GONE);
progress.setVisibility(View.VISIBLE);
final Handler handler = new Handler() {
@Override
public void handleMessage(Message message) {
System.out.println("Set image at" + position
+ " Image Name :: " + imageurl);
progress.setVisibility(View.GONE);
image.setImageBitmap((Bitmap) message.obj);
image.setVisibility(View.VISIBLE);
}
};
Thread thread = new Thread() {
@Override
public void run() {
Bitmap drawable = LoadImageFromWebOperations(imageurl);
Message message = handler.obtainMessage(1, drawable);
handler.sendMessage(message);
}
};
thread.start();
return v;
}
You can use a list of Bitmap images. At first set all the Bitmap in the list as null. And in the method getView check whether the Bitmap in the position of the Bitmap list is null or not. If null then show the progressBar and download the image and save the image in the list.
For example the images List name is images. Then the code in the getView method will be as follows:
Hope, you have understood what I have meant. 🙂