Android: Bitmaps arrayList

1

As I generate a bitmap arraylist in my setImage setter, look for some examples but I only found the following example

My code

public class CheckIn {
private int folio;
private String customer;
private String delivery;
private ArrayList<Bitmap> images;

public int getFolio() {
    return folio;
}

public void setFolio(int folio) {
    this.folio = folio;
}

public String getCustomer() {
    return customer;
}

public void setCustomer(String customer) {
    this.customer = customer;
}

public String getDelivery() {
    return delivery;
}

public void setDelivery(String delivery) {
    this.delivery = delivery;
}

public ArrayList<Bitmap> getImages() {
    return images;
}

public void setImages(ArrayList<Bitmap> images) {
    this.images = images;
}
}

Example that I found

public class City {
protected int id;
protected String name;
protected String data;
protected Bitmap photo;

public City(int id, String name) {
    this.id = id;
    this.name = name;
}

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public String getData() {
    return data;
}

public void setData(String data) {
    this.data = data;
    try {
        byte[] byteData = Base64.decode(data, Base64.DEFAULT);
        this.photo = BitmapFactory.decodeByteArray( byteData, 0, 
            byteData.length);
    }
    catch(Exception e) {
        e.printStackTrace();
    }
}

public Bitmap getPhoto() {
    return photo;
}

}

The example only sets a bitmap in setData but I have not only one image but several

    
asked by Javier fr 29.11.2016 в 15:39
source

2 answers

1

According to the example you found:

You define the Array that will contain the Bitmaps:

ArrayList<Bitmap> bitmapArray = new ArrayList<Bitmap>();

then add each Bitmap to your Array:

public void setData(String data) {
    this.data = data;
    try {
        byte[] byteData = Base64.decode(data, Base64.DEFAULT);
        this.photo = BitmapFactory.decodeByteArray( byteData, 0, 
            byteData.length);
        //Agregas cada Bitmap a tu Array:
        bitmapArray.add(this.photo);
    }
    catch(Exception e) {
        e.printStackTrace();
    }

In the case of your original code:

    //Defines tu ArrayList
    ArrayList<Bitmap> bitmapArray = new ArrayList<Bitmap>();

   //Método para obtener el ArrayList de Bitmaps.
    public ArrayList<Bitmap> getImages() {
        return bitmapArray;
    }

    //Al almacenar un Bitmap este será agregado a el ArrayList de bitmaps el cual será obtenido por getImages().    
    public void setImages(ArrayList<Bitmap> images) {
        this.images = images;
        bitmapArray.add(images);
    }
    
answered by 29.11.2016 / 16:28
source
1

Your list ArrayList<Bitmap> images; has the method add , to add one or more elements to your list simply call images.add(); Since you have many Bitmap , you can go through them if you have them previously in an arrangement or , add it one by one if you know what they are. In this case, go through the tuarreglo arrangement that would be all your Bitmap and add them to your ArrayList .

CheckIn checkin = new Checkin();
ArrayList<Bitmap> images = new ArrayList<Bitmap>();
//recorrer los BitMaps y los agregar a tu arraylist
for(int i = 0; i < tuarreglo.length ;i++ ){
   images.add(tuarreglo[i]);
}
checkin.setImages(images);
//o tambien checkin.images = images;
    
answered by 29.11.2016 в 16:02