Swipeable-RecyclerView icon indicating copy to clipboard operation
Swipeable-RecyclerView copied to clipboard

ClassCastException in SwipeAdapter

Open pkleczko opened this issue 8 years ago • 4 comments

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));
}

pkleczko avatar Sep 21 '17 07:09 pkleczko

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.

taltstidl avatar Sep 21 '17 08:09 taltstidl

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 avatar Sep 21 '17 11:09 pkleczko

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

pkleczko avatar Sep 21 '17 11:09 pkleczko

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.

taltstidl avatar Sep 21 '17 16:09 taltstidl