Android: Remove data from an Object ArrayLIst

4

I have a problem extracting data from an Object ArrayList. This is my object

public class ImageData {
    private int id;
    private String name;
    private Bitmap bitmap;
    private String path;

    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 Bitmap getBitmap() {
        return bitmap;
    }

    public void setBitmap(Bitmap bitmap) {
        this.bitmap = bitmap;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }
}

Then in another Object I have an ArrayList of this object

public class CheckIn {
    private int folio;
    private String customer;
    private String delivered;
    private ArrayList<ImageData> images;
//    private ArrayList<String> imagePath;

    private static CheckIn instanceCheckIn;

    private CheckIn(){
    }//constructor

    public static CheckIn getInstance() {

        if (instanceCheckIn == null)
            instanceCheckIn = new CheckIn();

        return instanceCheckIn;
    }

    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 getDelivered() {
        return delivered;
    }

    public void setDelivered(String delivered) {
        this.delivered = delivered;
    }

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

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

But what I want to do is just extract the Bitmaps from the ArrayList because later I'll put them in an ImageView

    
asked by Javier fr 19.12.2016 в 17:13
source

4 answers

2

In your ImageData class you have already made the get and set of each of its properties. Therefore, to obtain its values it would be enough simply to go through this list, and call its get method to manipulate it and to give it to your ImageView :

CheckIn checkin = new CheckIn();
for (ImageData object: checkin.getImages()) {
    //Aqui manipulas el valor y los vas seteando a tus imagenes
    object.getBitmap();
}
    
answered by 19.12.2016 / 17:23
source
2

Then you would have to take the list of ImageData of your object CheckIn and go through it getting all the bitmaps and saving them in a list. It would be something like the code that I put you below:

CheckIn c;
ArrayList<Bitmap> bitmaps = new ArrayList();

for( ImageData img : c.getImages()){
     bitmaps.add(img.getBitmap());
}
    
answered by 19.12.2016 в 17:21
2

Another way to do it if you use java 8 is with lambda expressions

checking.getImages().forEach( o -> {
   // acá manipulas el objeto "o" 
});

If you want to get the BitMap would be something like that:

List<BitMap> bitMaps = new ArrayList<>();

checking.getImages().forEach( o -> bitMaps.add(o.getBitMap());
    
answered by 19.12.2016 в 17:37
2

In both objects you have methods to save the images / images as well as to obtain the image / images, the ImageData object can store an image, while CheckIn, stores a list of images.

Object ImageData :

//Obtiene imagen
public Bitmap getBitmap() {
    return bitmap;
}
//Guarda imagen
public void setBitmap(Bitmap bitmap) {
    this.bitmap = bitmap;
}

Object CheckIn :

//Obtiene lista de imagenes.
public ArrayList<ImageData> getImages() {
    return images;
}

//Guarda lista imagenes.
public void setImages(ArrayList<ImageData> imageDatasArray) {
    this.images = imageDatasArray;
}

Therefore, to obtain an image from the list of images and add it to an ImageView, you do the following:

//Instancias la clase CheckIn
CheckIn checkin = new CheckIn();
//Obtienes un arrayList que obtiene el listado de imagenes.
ArrayList<ImageData> listaImagenes =  checkin.getImages();

Bitmap bitmap;
for (ImageData image: listaImagenes )) {
    //Obtiene imagenes
    bitmap = image.getBitmap();
}

You could also get the bitmap in the ArrayList depending on the index in the list, for example the second element (index 1):

Bitmap bitmap = listaImagenes.get(1);

When you get the Bitmap you can use the setImageBitmap to add the image to your ImageView:

myImageView.setImageBitmap(bitmap);
    
answered by 19.12.2016 в 17:48