taltstidl / Swipeable-RecyclerView

A library that provides an easy and customizable way to implement a swipe to dismiss pattern with RecyclerView.
Apache License 2.0
87 stars 17 forks source link

ClassCastException in SwipeAdapter #21

Open pkleczko opened 6 years ago

pkleczko commented 6 years ago

Hi,

In SwipeAdapter there is a cast from holder view to SwipeItem. However, in your example there is no SwipeItem layout as a root of item view. Also wrapping my item layout into SwipeItem doesn't help. Is there sth I forget to add?

java.lang.ClassCastException: android.widget.FrameLayout cannot be cast to com.tr4android.recyclerviewslideitem.SwipeItem
    at com.tr4android.recyclerviewslideitem.SwipeAdapter.onBindViewHolder(SwipeAdapter.java:45)
    at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:6356)`
@Override
public RecyclerView.ViewHolder onCreateSwipeViewHolder(final ViewGroup parent, final int position) {
    ViewPatientHealthItemBinding binding = ViewPatientHealthItemBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);
    return new ViewHolder(binding.getRoot());
}

@Override
public void onBindSwipeViewHolder(final RecyclerView.ViewHolder viewHolder, final int position) {
    ((ViewHolder) viewHolder).populateData(items.get(position));
}
taltstidl commented 6 years ago

Hi @pkleczko. Try changing the last parameter of your inflate call to true, so it looks like this:

ViewPatientHealthItemBinding.inflate(LayoutInflater.from(parent.getContext()), parent, true);

That way your list item layout will be directly added as a subview of the SwipeItem that handles the swipe to dismiss feature. Otherwise it's not attached and it will fail to find the corresponding SwipeItem. See here for more details.

pkleczko commented 6 years ago

Hi @TR4Android,

I've tried this but still have the same error. I cleaned and rebuilt app and crash is exactly the same.

ViewPatientHealthItemBinding binding = ViewPatientHealthItemBinding.inflate(LayoutInflater.from(parent.getContext()), parent, true);

pkleczko commented 6 years ago

Don't uderstand why, but without data binding it works. Maybe there is sth with root view.

taltstidl commented 6 years ago

Then it's probably an issue with the data binding library. Unfortunately I don't currently have the time to commit to fixing this issue, so any investigation on this would be greatly appreciated. Thanks for reporting this @pkleczko.