Meetic / Shuffle

An easy to use swiping-view for Android
886 stars 83 forks source link

Error when Using ViewHolder #23

Closed RowlandOti closed 6 years ago

RowlandOti commented 6 years ago

Whenever the user selects images and adds them to the ViewHolder, the app keeps crashing with the following stack trace:

capture

My code is very basic, and yet the solution to this bug evades me. see the code below:

class ImageShuffleAdapter : Shuffle.Adapter<ImageShuffleViewHolder>() {

        private var uris: List<Uri> = emptyList()

        override fun onCreateViewHolder(parent: ViewGroup?, type: Int): ImageShuffleViewHolder {
            val view = LayoutInflater.from(parent!!.context).inflate(R.layout.content_product_images_shuffle, parent, false)
            return ImageShuffleViewHolder(view)
        }

        override fun onBindViewHolder(viewHolder: ImageShuffleViewHolder?, position: Int) {
            viewHolder!!.bind(this.uris.get(position), position)
        }

  // More coe
}

I think there is a bug with the library. Could you have sone thoughts?

RowlandOti commented 6 years ago

No response thus far, so I had to resolve it myself. It seems the library is no longer maintained - I could help if the response is given. For anyone landing here, I solved it by using:

draggableViewContent.removeAllViews();
ViewGroup parent = (ViewGroup) viewHolder.itemView.getParent();
if (parent != null) {
         parent.removeView(viewHolder.itemView);
 }
draggableViewContent.addView(viewHolder.itemView);