Create a custom adapter by subclassing VirtualListViewAdapterBase
mainFor complex data sources like SQLite, subclass VirtualListViewAdapterBase<TSection, TItem>. This allows you to implement custom logic for retrieving sections and items while managing your own caching strategy. Always call base.InvalidateData() and clear your local caches inside your InvalidateData() override.
public class SQLiteAdapter : VirtualListViewAdapterBase<object, ItemInfo>
{
public SQLiteAdapter() : base() { Db = new Database(...); }
public Database Db { get; }
int? cachedItemCount = null;
public override int GetNumberOfItemsInSection(int sectionIndex)
=> cachedItemCount ??= Db.ExecuteScalar<int>("SELECT COUNT(Id) FROM Items");
public override string GetItem(int sectionIndex, int itemIndex)
=> Db.FindWithQuery<ItemInfo>("SELECT * FROM Items ORDER BY Id LIMIT 1 OFFSET ?", itemIndex);
public override void InvalidateData()
{
cachedItemCount = null;
base.InvalidateData();
}
}