Reputation: 517
I am using Delphi 10.3.1 (Firemonkey FMX) to build android and iOS app. I have a TListView, live binding with a AdapterBindSource. My problem is: new records does not appear after Adapter refreshed.
==============
==============
first I get records from Rest Server and converted into a 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;
then the records show on ListView which live bindings with the AdapterBindSource
When click on Refresh button, I trigger to get data from Rest server again, I do free the FList and re-create it
FreeAndNil(FList);
FList := TDataList.Create; // re-create the list, then create Tdata object and add to it again.
then I refresh the adapter
AdapterBindSource1.Adapter.Refresh;
AdapterBindSource1.Refresh;
here the 3 old records are refreshed successfully, modified data are displayed correctly, however, new record is not showing, the TListView still showing 3 records only.
Notes:
How can I resolve this? is there something I missing like to refresh the TListView? Or my BindSourceAdapter refresh logic is wrong?
Thanks for any help.
Upvotes: 1
Views: 1351
Reputation: 517
I found a solution to refresh the TListView.
The issue happened due to re-create of TObjectList here:
FreeAndNil(FList);
FList := TDataList.Create; // re-create the list, then create Tdata object and add to it again.
Free the List and re-create caused the issue. I changed it to clear the list and add new objects to it.
FList.Clear();
// then add objects to it again, such as FList.AddRange(...)
then AdapterBindSource refreshed successfully.
If the TObjectList free and re-created, it no more used by the Adapter correctly.
Upvotes: 1