本文整理匯總了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);
}