Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 领域数据更改时更新ListVIew中的数据_Android_Listview_React Native_Realm - Fatal编程技术网

Android 领域数据更改时更新ListVIew中的数据

Android 领域数据更改时更新ListVIew中的数据,android,listview,react-native,realm,Android,Listview,React Native,Realm,我在RN应用程序中使用Realm,其设置如下: this.classes = realm.objects('Notebook').sorted('active'); this.classes.addListener((name, changes) => { console.log("changed: " + JSON.stringify(changes)); console.log("Number of items: "

我在RN应用程序中使用Realm,其设置如下:

this.classes = realm.objects('Notebook').sorted('active');
this.classes.addListener((name, changes) => {
        console.log("changed: " + JSON.stringify(changes));
        console.log("Number of items: " + this.classes.length);
});

var dataSource = new ListView.DataSource(
        {rowHasChanged: (r1, r2) => r1.name !== r2.name});

this.state = {
  dataSource: dataSource.cloneWithRows(this.classes),
  src: dataSource
};
起初一切都很好。插入新对象时,如下所示:

realm.write(() => {
    realm.create('Notebook', {
        ...
    });
});
我在我的侦听器中得到通知,某些内容已更改。然而,我看到的是:

更改:{“删除”:[]、“插入”:[]、“修改”:[]

项目数目:8


我认为应该在“插入”中列出一些内容。此外,项目的数量始终是添加新数据之前存在的数量。有人能告诉我是否设置错误吗?

有什么理由不使用flatlist吗?通过将
直接传递到数据源,无需添加侦听器。我需要一个侦听器,以便知道何时添加/删除/更新类,并相应地更新我的ListView。