I need to show an image for 1 second since I spend 1 second to hide it for 1 second, and then show the next image in the list for 1 second and then hide it for 1 second until I scan all the images in the list.
My problem is that my code only shows me the first image and the next one does not show them, it leaves them invisible and goes through the whole list, but only shows the first one.
Code:
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
private void showNextImage() {
// loads the image at position currentPosition
final Bits item = L.get(currentPosition);
imageBit.setImageBitmap(BitmapFactory.decodeFile(item.getbImage()));
handler.postDelayed(new Runnable() {
@Override
public void run() {
imageBit.setImageBitmap(BitmapFactory.decodeFile(item.getbImage()));
}
},1000);
handler.postDelayed(new Runnable() {
@Override
public void run() {
nameBit.setText(item.getbText());
imageBit.setVisibility(View.INVISIBLE);
}
},1000);
currentPosition++; // updates the current position
if (L.size() > currentPosition) { // more images to show?
// loads the next image after some delay
handler.postDelayed(new Runnable() {
@Override
public void run() {
imageBit.setVisibility(View.VISIBLE);
showNextImage();
}
}, 1000); // in millis, 1000 for one second delay
}
}