Using the RealmObject with Databinding


#1

I’m using the RealmObject model for databinding. It worked fine but now I want my views to update when data changes and I implemented Observable.

The model is:

public class RealmArticle extends RealmObject implements Observable {

    public RealmArticle() {
    }

    private PropertyChangeRegistry registry =
            new PropertyChangeRegistry();

    @Bindable
    public String getCountText() {
        return countText;
    }

    public void setCountText(String countText) {
        this.countText = countText;
        registry.notifyChange(this, BR.obj);
    }

    @Override
    public void addOnPropertyChangedCallback(OnPropertyChangedCallback callback) {
        registry.add(callback);
    }

    @Override
    public void removeOnPropertyChangedCallback(OnPropertyChangedCallback callback) {
        registry.remove(callback);
    }
}

The problem is that RealmObject doesn’t support the fields of PropertyChangeRegistry type.

Android studio says: Error:(18, 8) error: Field "registry" of type "android.databinding.PropertyChangeRegistry" is not supported.

Is there a way to implement this interface without violating RealmObject functionality?


#2

You can put the @Ignore annotation on the field, that should enable you to use it. See e.g. https://github.com/Zhuinden/realm-databind-experiment/blob/master/app/src/main/java/com/zhuinden/realmdatabind/realm/objects/Post.java


#3

hey how had you binded data with Realm in Android?