Search code examples
androidandroid-recyclerviewandroid-imageview

Issue working with a recyclerview


I've got a problem using the recycler view on my android app. Everything works fine, until I add 4/5 rows to the recycler view. And application crashes.

This is the model of the recycler view, in the application I add dynamically Images and Text in the text view.

<ImageView
    android:id="@+id/imageIDEntryList"
    android:layout_width="90dp"
    android:layout_height="90dp"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:srcCompat="@drawable/ic_image_grey_24dp" />

<TextView
    android:id="@+id/entryNameRecycler"
    android:layout_width="0dp"
    android:layout_height="90dp"
    android:gravity="left|center"
    android:text="TextView"
    android:textColor="@android:color/black"
    android:textSize="35dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toEndOf="@+id/imageIDEntryList"
    app:layout_constraintTop_toTopOf="parent" />

I'm using jpeg format to save the images on recycler view. Is the crash caused by the excessive size of the images? I've also used a library (imagepicker) for manage images and put in the rows of recycler view.

this is the issue:

android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable

this is where I add the image to imageView

if(requestCode == Keys.IMAGE_INTENT_REQUEST_CODE && resultCode == RESULT_OK) {
        final Uri imageUri = Uri.fromFile(new File(ImagePicker.getFirstImageOrNull(data).getPath()));
        try {
            bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), imageUri);
        }catch(IOException e){
            e.printStackTrace();
        }
        imageView.setImageBitmap(bitmap);
    }

How is the crash caused?


Solution

  • Most use Picasso or Glide for updating images in RecyclerView. These libraries are opensource and are much more efficient than using Bitmap.

    With Picasso, you can load in ImageView as simple as

    Picasso.get().load(yourUri).into(imageView);
    Also it will run efficiently making your recycler view scroll smoothly.