Amix Amix - 1 year ago 224
Android Question

how to convert listview to recyclerview?

I have problem when I want to use these codes below and I use recyclerview in my code but I think its listview anybody can help me?

public ListViewSwipeGesture(RecyclerView listView, TouchCallbacks Callbacks, MainListFragment context){
ViewConfiguration vc = ViewConfiguration.get(listView.getContext());
mSlop = vc.getScaledTouchSlop();
mMinFlingVelocity = vc.getScaledMinimumFlingVelocity() * 16;
mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
mListView = listView;
activity = context;
tcallbacks = Callbacks;
SwipeType = Double;

when I use : mListview = listview;
I have an error.
and the error is :
Error:(103, 21) error: incompatible types: RecyclerView cannot be converted to ListView

Answer Source

You can not cast ListView into RecyclerView, As per the Java, Parent class can only hold reference of child object and also only you can cast a base class into it's child class (and that is only when child is instanceof that class).

So here listview and Recyclerview both don't have any relationship so you can not cast listview into recyclerview

Below is the class hierarchy of RecyclerView:

   ↳    android.view.View
       ↳    android.view.ViewGroup

Below is the class hierarchy of ListView:

   ↳    android.view.View
       ↳    android.view.ViewGroup
           ↳    android.widget.AdapterView<android.widget.ListAdapter>
               ↳    android.widget.AbsListView
                   ↳    android.widget.ListView
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download