Show an ImageView and TextView Running [duplicate]

0

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();
}
    
asked by Exbaby 16.04.2017 в 08:02
source

1 answer

2

First try to create a list of Bitmaps called ItemsBitmap , declare currentPosition global and create a variable to store the bitmap global too:

public ArrayList<Bitmap> ItemsBitmap;
public Bitmap bitmap;
public currentPosition = 0;

Now initialize the list with the bitmaps before calling the showImages method:

ItemsBitmap = new ArrayList();

for(int i = 0; i < L.size(); i++){
   Bits item = L.get(i);
   ItemsBitmap.add(BitmapFactory.decodeFile(item.getbImage()));
}
showImages();

Here's the method:

@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
private void showImages() {
        bitmap = ItemsBitmap.get(currentPosition);
        imageBit.setImageBitmap(bitmap);

        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 = 0; // esto hace que la bandera no crezca mucho
                    imageBit.setVisibility(View.VISIBLE);
                }
                else {
                    bitmap = ItemsBitmap.get(currentPosition);
                    imageview.setImageBitmap(bitmap);
                    currentPosition++;
                    if (ItemsBitmap.size() == currentPosition) {
                        currentPosition = 0; // Esto hace que se vuelva a repetir la lista de Bitmaps
                    }
                    imageBit.setVisibility(View.GONE);
                }
                number++;
            }
            public void onFinish() {

                if (continuar) {
                    this.start();
                }
            }
        }.start();
    }

I tried it and it works perfect, let me know if it works for you.

    
answered by 18.04.2017 / 04:46
source