我正在使用Delphi 10.3.1(Firemonkey FMX)构建Android和iOS应用。我有一个TListView,与AdapterBindSource实时绑定。我的问题是:适配器刷新后,不会出现新记录。
==============
==============
首先,我从Rest Server获取记录并将其转换为TObjectList
TData : class(TObject) ... // a class stored some data
TDataList = class(TObjectList<TData>)
// then I get data from Rest Server and created FList, it is a Form private variable
FList := TDataList.Create; // a private Form variable
// create Tdata objects and add to FList .....
var ABindSourceAdapter: TBindSourceAdapter;
// ....
ABindSourceAdapter := TListBindSourceAdapter<TData>.Create(self, FList, True);
AdapterBindSource1.Adapter := ABindSourceAdapter;
AdapterBindSource1.Active := true;
然后记录显示在ListView上,这些记录与AdapterBindSource进行实时绑定
当单击“刷新”按钮时,我再次触发以从Rest服务器获取数据,我释放了FList并重新创建了它
FreeAndNil(FList);
FList := TDataList.Create; // re-create the list, then create Tdata object and add to it again.
然后刷新适配器
AdapterBindSource1.Adapter.Refresh;
AdapterBindSource1.Refresh;
此处成功刷新了3条旧记录,正确显示了已修改的数据,但是,未显示新记录,TListView仍仅显示3条记录。
注释:
我该如何解决?我缺少想刷新TListView的东西吗?还是我的BindSourceAdapter刷新逻辑错了?
感谢您的帮助。
答案 0 :(得分:0)
我找到了刷新TListView的解决方案。
发生此问题是由于在此处重新创建了TObjectList:
The ansible playbook is as follows---
- hosts: all
become: yes
tasks:
- name: Chenking ping
ping:
- name: Update packages
apt:
name: apache2
update_cache: yes
state: present
- name: restart apache2 server
service:
name: apache2
enable: yes
state: restarted
- name: install php module
apt:
name: "{{ item }}"
state: present
with_items:
- php
- libapache2-mod-php5
- php-mcrypt
- php-mysql
- name: restart apache2 afetr restart
service:
name: apache2
enable: yes
state: restarted
释放列表并重新创建导致此问题。我更改了它以清除列表并向其中添加新对象。
FreeAndNil(FList);
FList := TDataList.Create; // re-create the list, then create Tdata object and add to it again.
然后AdapterBindSource成功刷新。
如果TObjectList释放并重新创建,则适配器将不再正确使用它。