Go through an ArrayList and show one by one

3

I am using a for to go through a list of objects, but it only shows me the last one, in the console if it shows me that it goes through all, but in the Imageview it only shows the last one.

Code:

if(!L.isEmpty()){
      for (Bits bits : L){
         imageBit.setImageBitmap(BitmapFactory.decodeFile(bits.getbImage()));
         nameBit.setText(bits.getbText());
       }
   }

but I need to show one by one in the imageview , for example Show the first, then the second, and so on until I finish, I do not know if it takes a TIMER or as power does?

    
asked by Exbaby 14.04.2017 в 21:10
source

2 answers

2

You can change the content of a ImageView by using:

ImageView iView;
// instar iView segun layout
iView.setImageDrawable(drawable);

So if you get your Drawable from an ArrayList, you can update the content of ImageView one by one.

Instead of a Timer , use a Handler with a Runnable to update the image. This guarantees that the update is done from the UI thread.

// en tu activity
Handler mHandler = new Handler();
// y tienes por ejemplo un ArrayList con los Drawable
ArrayList<Drawable> imagenes;

public class Actualizador implements Runnable{
    int i=0;
    @Override
    public void run(){
        if (i<imagenes.size()){
            iView.setImageDrawable(imagenes.get(i++));
            mHandler.postDelayed(this,3000); // reejecutar despues de 3000 ms
        }
    }
}

mHandler.post(new Actualizador());

Now, if you want to build the bitmap image from a bit array, your code does exactly what you ask: iterate over the array and put the current bits in the image. If you want to build an image that as a final result has all bits as content, you have to concatenate the Bits instead of replacing them. In this case you have to elaborate a bit more as you intend to build your image from the components.

    
answered by 14.04.2017 в 21:51
0

When using an Imageview you can only enter a single value. You can not display 10 images in 1 single imageView. Try using a Listview and you can see them all.

    
answered by 14.04.2017 в 21:20