Search code examples
javaandroidrealm

Cannot pass parameters to super(); in a class's constructor that extends RealmBaseAdapter (Realm)


I have a problem that I cannot pass the parameters "context, realmResults, automaticUpdate" to super(); in a class's constructor that extends RealmBaseAdapter. See my code and the screenshot to be clear for you.

* My code:

package com.twitter.i_droidi.notah;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import io.realm.RealmBaseAdapter;
import io.realm.RealmObject;
import io.realm.RealmResults;

public class RealmModelAdapter <T extends RealmObject> extends RealmBaseAdapter<T> {

    public RealmModelAdapter(Context context, RealmResults<T> realmResults, boolean automaticUpdate)
    {
        super(context, realmResults, automaticUpdate);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        return null;
    }
}

* Screenshot:

* Realm version: 1.0.1

* Android Studio version: 2.1.2


Solution

  • In Realm 0.90.0+, you should be using the separate realm-android-adapters project (currently compile 'io.realm:android-adapters:1.3.0'). In which RealmBaseAdapter has the following constructor signature:

    public RealmBaseAdapter(@NonNull Context context, @Nullable OrderedRealmCollection<T> data) {
       ....
    }
    

    So you would have

    super(context, realmResults);
    

    In Realm 2.0.0+, the context parameter is no longer needed.

    public RealmBaseAdapter(@Nullable OrderedRealmCollection<T> data) {
    
    public RealmRecyclerViewAdapter(@Nullable OrderedRealmCollection<T> data, boolean autoUpdate) { // <-- autoUpdate always recommended to be `true`