java.util.Listandroid.widget.ImageView "is not supported error android

0

I am trying to pass a List (From an activity, AddClothesActivity) to create a class (Clothes). This step of information I do in the constructor.

The problem is that I miss a compilation error in which it says: Field "clothesList" of type "java.util.List" is not supported. where clothesList is a variable type List

Clothes class:

public class Clothes extends RealmObject{


    @PrimaryKey
    private int id;
    @Required
    private String name;
    @Required
    private String description;
    private float stars;
    private List<ImageView> clothesList;

    public Clothes() {
    }

    public Clothes(String name, String description, float stars, List<ImageView> clothesList ) {
        this.id = MyApp.CityID.incrementAndGet();
        this.name = name;
        this.description = description;
        this.stars = stars;
        this.clothesList = clothesList;
    }

AddClothesActivity class:

Declaration

private ImageView photoGallery;
private List<ImageView> photos;

I add the photos I make or take from the gallery:

Uri path = data.getData();
photoGallery.setImageURI(path);
photos.add((photoGallery));

And I pass them with the constructor:

Clothes city = new Clothes(name, description, stars, photos);
    
asked by CMorillo 22.03.2018 в 12:51
source

1 answer

2

Real does not recognize the fields of type List , you have to use RealmList :

public class Clothes extends RealmObject{

    //...

    private RealList<ImageView> clothesList;

   //...

Because ImageView is not supported, change it to type byte[] that if supported by real. To convert byte[] you can use the following class ImageViewHelper.java :

public class ImageViewHelper
{
   public static byte[] ToByteArray(ImageView imageView)
   {
        Bitmap bitmap = ((BitmapDrawable) imageView.getDrawable()).getBitmap();
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
        byte[] bytes = stream.toByteArray();
        return bytes
   }

   public static void bytesToImageView(byte[] data, ImageView target)
   {
        Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);

        target.setImageBitmap(Bitmap.createScaledBitmap(bmp, target.getWidth(),
                target.getHeight(), false)));
   }
}

The use of the method to convert byte [] to ImageView would be like this:

ImageView img = (ImageView)findViewById(R.id.imageView);
ImageViewHelper.bytesToImageView(aquiLosBytes, img);

// listo, img ya tiene la imagen.
    
answered by 22.03.2018 в 13:14