Swipeable-RecyclerView
Swipeable-RecyclerView copied to clipboard
ClassCastException in SwipeAdapter
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));
}
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.
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);
Don't uderstand why, but without data binding it works. Maybe there is sth with root view.
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.