Show a ImageView
for 1s and after the time the image is deleted and then show a TextView
for 1s, and so on until you go through the% List
. way to do it:
Code:
This way it is working:
Thanks to the contribution of:
Andrespengineer
Declarations ...
private int currentPosition = 0;
public ArrayList<Bitmap> ItemsBitmap;
public Bitmap bitmap;
public Bits items;
Initialize:
ItemsBitmap = new ArrayList<>();
for(int i = 0; i < L.size(); i++){
Bits item = L.get(i);
ItemsBitmap.add(BitmapFactory.decodeFile(item.getbImage()));
}
for (int x = 0; x < L.size(); x++){
Bits item = L.get(x);
nameBit.setText(item.getbText());
}
showImages();
Method:
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
private void showImages() {
new CountDownTimer(2000, 1000) {
boolean continuar = true; // Si quieres que se detenga, vuelve continuar false en algun momento
int number = 0;
public void onTick(long millisUntilFinished) {
if(number % 2 != 0) {
if(number == 101)
number = -1; // esto hace que la bandera no crezca mucho
imageBit.setVisibility(View.VISIBLE);
nameBit.setVisibility(View.GONE);
}
else {
bitmap = ItemsBitmap.get(currentPosition);
imageBit.setImageBitmap(bitmap);
items = L.get(currentPosition);
nameBit.setText(items.getbText());
currentPosition++;
if (ItemsBitmap.size() == currentPosition) {
currentPosition = 0; // Esto hace que se vuelva a repetir la lista de Bitmaps
}
imageBit.setVisibility(View.GONE);
if (L.size() == currentPosition){
currentPosition = 0;
}
nameBit.setVisibility(View.VISIBLE);
}
number++;
}
public void onFinish() {
if (continuar) {
this.start();
}
}
}.start();
}