我有RecyclerView.Adapter
使用八个不同的RealmObjects
public class SearchAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private String tag;
private Realm realm;
private RealmResults<HashtagObject> hashtags;
private RealmResults<SearchtagObject> searchtags;
etc.
public SearchAdapter(Realm realm,final String tag) {
setHasStableIds(true);
RealmChangeListener realmChangeListener = new RealmChangeListener() {
@Override
public void onChange(Object element) {
notifyDataSetChanged();
}
};
this.realm=realm;
this.tag=tag;
this.hashtags = realm.where(HashtagObject.class).findAll();
this.searchtags = realm.where(SearchtagObject.class).findAll();
...
this.hashtags.addChangeListener(realmChangeListener);
this.searchtags.addChangeListener(realmChangeListener);
...
}
}
我正在尝试创建RealmRecyclerViewAdapter
构造函数,但那里有OrderedRealmCollection
。如何将OrderedRealmCollection
用于我的计划?
第二个问题是notifyDataSetChanged()
的问题。每次Realm数据库更改时,都会激活onBindViewHolder
。但是我需要这种方法只有在用户与recyclerView交互时才能工作,而不是永久工作。以及notifyDataSetChanged()
方法在RealmRecyclerViewAdapter
中的工作原理。