Is it possible to make CursorAdapter be set in recycleview, just like ListView?

I didn’t google out a solution till now to replace listview in my project, because I need to use the cursor linked with the sqlite.

Old way as followed:
listview.setAdapter(cursorAdapter) in this way, I can get the cursor to deal with data in database

  • Speech to Text from own sound file
  • Admob account suspended due to “invalid activity on the AdSense ads hosted on your website”
  • Getting 'BadTokenException: Unable to add window' when trying to show Facebook dialog - Android
  • Why do 9-patch graphics size correctly in the emulator but not on a phone?
  • Whats the difference between Thread.setPriority() and android.os.Process.setThreadPriority()
  • Testing ViewPager with Espresso. How perfom action to a button of an Item?
  • but now, recycleview.setAdapter(recycleview.adapter) it doesn’t recognize the adapter extending BaseAdapter

    so anyone can give me a hand?

    Related posts:

    Duplicate files while including butterknife with gradle
    Are there any Observers written In RecyclerView.Adapter to know if dataset has been changed?
    Wait for other view animation end
    What is the purpose of IntentSender?
    Android NinePatch .png file format?
    VectorDrawable: Android loads xhdpi PNG's instead of the vector resource
  • Simulate slow network on Android simulator
  • How can I focus on a collapsible action view EditText item in the action bar (when it is expanded) and force the soft keyboard to open?
  • GCM push notification is not showing in some devices when app is not running
  • Android apps, communicating with a device plugged in the USB port
  • ViewHolder pattern correctly implemented in custom CursorAdapter?
  • Android - Remove action button from notification
  • 2 Solutions collect form web for “Is it possible to make CursorAdapter be set in recycleview, just like ListView?”

    The new RecyclerView works with a new RecyclerView.Adapter base class.
    So it doesn’t work with the CursorAdapter.

    Currently there is no default implementation of RecyclerView.Adapter available.

    May be with the official release, Google will add it.

    Implementing it yourself is actually quite simple:

    public class CursorAdapter extends RecyclerView.Adapter<ViewHolder>{
    
        Cursor dataCursor;
    
        @Override
        public int getItemCount() {
            return (dataCursor == null) ? 0 : dataCursor.getCount();
        }
    
    
        public void changeCursor(Cursor cursor) {
            Cursor old = swapCursor(cursor);
            if (old != null) {
              old.close();
            }
          }
    
         public Cursor swapCursor(Cursor cursor) {
            if (dataCursor == cursor) {
              return null;
            }
            Cursor oldCursor = dataCursor;
            this.dataCursor = cursor;
            if (cursor != null) {
              this.notifyDataSetChanged();
            }
            return oldCursor;
          }
    
        private Object getItem(int position) {
            dataCursor.moveToPosition(position);
            // Load data from dataCursor and return it...
          }
    
    }
    
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.