本文整理汇总了Java中io.realm.RealmResults.addChangeListener方法的典型用法代码示例。如果您正苦于以下问题:Java RealmResults.addChangeListener方法的具体用法?Java RealmResults.addChangeListener怎么用?Java RealmResults.addChangeListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.realm.RealmResults
的用法示例。
在下文中一共展示了RealmResults.addChangeListener方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupAdapter
import io.realm.RealmResults; //导入方法依赖的package包/类
public void setupAdapter(RealmResults<Post> posts) {
posts.addChangeListener(changeListener);
adapter = new PostAdapter(posts);
recyclerView.setLayoutManager(new LinearLayoutManager(App.getAppContext()));
recyclerView.setEmptyView(emptyView);
recyclerView.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
示例2: subscribeDataChange
import io.realm.RealmResults; //导入方法依赖的package包/类
@Override
public void subscribeDataChange(Object dataIdentity, final DataChangeListener listener) {
if (dataIdentity instanceof RealmResults) {
RealmResults<RealmObject> realmResults = (RealmResults<RealmObject>) dataIdentity;
realmResults.addChangeListener(new RealmChangeListener<RealmResults<RealmObject>>() {
@Override
public void onChange(RealmResults<RealmObject> element) {
if (listener != null) {
listener.onChange();
}
}
});
}
}
示例3: expectSimpleCommit
import io.realm.RealmResults; //导入方法依赖的package包/类
@Test
@RunTestInLooperThread
@RunTestWithRemoteService(remoteService = SimpleCommitRemoteService.class, onLooperThread = true)
public void expectSimpleCommit() {
looperThread.runAfterTest(remoteService.afterRunnable);
remoteService.createHandler(Looper.myLooper());
final SyncUser user = UserFactory.getInstance().createDefaultUser(Constants.AUTH_URL);
String realmUrl = Constants.SYNC_SERVER_URL;
final SyncConfiguration syncConfig = new SyncConfiguration.Builder(user,realmUrl)
.directory(looperThread.getRoot())
.build();
final Realm realm = Realm.getInstance(syncConfig);
final RealmResults<ProcessInfo> all = realm.where(ProcessInfo.class).findAll();
looperThread.keepStrongReference(all);
all.addChangeListener(new RealmChangeListener<RealmResults<ProcessInfo>>() {
@Override
public void onChange(RealmResults<ProcessInfo> element) {
assertEquals(1, all.size());
assertEquals("Background_Process1", all.get(0).getName());
realm.close();
user.logout();
remoteService.triggerServiceStep(SimpleCommitRemoteService.stepB_closeRealmAndLogOut);
looperThread.testComplete();
}
});
remoteService.triggerServiceStep(SimpleCommitRemoteService.stepA_openRealmAndCreateOneObject);
}
示例4: expectALot
import io.realm.RealmResults; //导入方法依赖的package包/类
@Test
@RunTestWithRemoteService(remoteService = ALotCommitsRemoteService.class, onLooperThread = true)
@RunTestInLooperThread
public void expectALot() throws Throwable {
looperThread.runAfterTest(remoteService.afterRunnable);
remoteService.createHandler(Looper.myLooper());
final SyncUser user = UserFactory.getInstance().createDefaultUser(Constants.AUTH_URL);
String realmUrl = Constants.SYNC_SERVER_URL;
final SyncConfiguration syncConfig = new SyncConfiguration.Builder(user,realmUrl)
.directory(looperThread.getRoot())
.build();
final Realm realm = Realm.getInstance(syncConfig);
final RealmResults<TestObject> all = realm.where(TestObject.class).findAllSorted("intProp");
looperThread.keepStrongReference(all);
final AtomicInteger listenerCalledCounter = new AtomicInteger(0);
all.addChangeListener(new RealmChangeListener<RealmResults<TestObject>>() {
@Override
public void onChange(RealmResults<TestObject> element) {
int counter = listenerCalledCounter.incrementAndGet();
int size = all.size();
if (size == 0) {
listenerCalledCounter.decrementAndGet();
return;
}
assertEquals(0, size % 100); // Added 100 objects every time.
assertEquals(counter * 100 - 1, all.last().getIntProp());
assertEquals("Str" + (counter * 100 - 1), all.last().getStringProp());
if (counter == 10) {
remoteService.triggerServiceStep(ALotCommitsRemoteService.stepC_closeRealm);
realm.close();
user.logout();
looperThread.testComplete();
} else {
remoteService.triggerServiceStep(ALotCommitsRemoteService.stepB_createObjects);
}
}
});
remoteService.triggerServiceStep(ALotCommitsRemoteService.stepA_openRealm);
remoteService.triggerServiceStep(ALotCommitsRemoteService.stepB_createObjects);
}
示例5: setPosts
import io.realm.RealmResults; //导入方法依赖的package包/类
public void setPosts(String criteria) {
POSTS = criteria;
//change the title
Title = (POSTS);
RealmResults<Post> posts = getPosts();
posts.addChangeListener(changeListener);
adapter = new PostAdapter(posts);
recyclerView.setAdapter(adapter);
}
示例6: start
import io.realm.RealmResults; //导入方法依赖的package包/类
@Override
public void start() {
sortOrder = appPreferences.getSortOrder();
RealmResults<Note> results = noteDataSource.loadNotes();
results.addChangeListener(callback);
}