在ROOM数据库中将arrayList绑定到observeForever()或observe()方法

时间:2019-11-25 12:05:05

标签: android arraylist observable android-room

我们如何在ROOM数据库arrayListobserveForever()方法中绑定observe()

 notificationModelArrayList = new ArrayList<>();
        NotificationRepository notificationRepository = new NotificationRepository(getApplicationContext());
        notificationRepository.getAllNotification().observe(NotificationActivity.this,new Observer<List<Notification>>() {
            @Override
            public void onChanged(@Nullable List<Notification> notifications) {
                for (org.jembi.careconekta.dbTables.Notification notification : notifications) {
                    System.out.println("-----------------------");
                    System.out.println(notification.getTitle());
                    System.out.println(notification.getMessage());
                    NotificationModel notificationModel = new NotificationModel();
                    notificationModel.setNotificationMsg(notification.getMessage());
                    notificationModelArrayList.add(notificationModel);
                }
            }
        });

System.out.println可以正常工作,但是notificationModel中没有添加notificationModelArrayList

0 个答案:

没有答案