LoadOnDemand triggeres *ListLoadOnDemand* only once

4 posts, 0 answers
  1. Namek
    Namek avatar
    7 posts
    Member since:
    Jul 2016

    Posted 21 Jun Link to this post

    I've just walk through this tutorial - http://docs.telerik.com/devtools/xamarin/controls/listview/features/listview-features-load-on-demand#automatic-mode
    for implementation of LoadOnDemand - which is triggered Automatically from XAML code behind.

    It work as expected at Android for me - *LoadOnDemand* event is triggered each time, i'm scrolling list down (and causing already last list existing elements visible). Each and every time, even if there is no objects be to be added. RadListView indeed didn't know if there are anything to be added to UI or not, that's why it fires *LoadOnDemand* event, in order to check it from code behind.

    The problem is, that *LoadOnDemand* triggers only once for me at iOS - after first scrolling down. When I'm scrolling again and again, and I'm reaching the end of the list, *LoadOnDemand* is not triggers again.

    It's not any specific case of my code - I'm just using simplest example form here - http://docs.telerik.com/devtools/xamarin/controls/listview/features/listview-features-load-on-demand#automatic-mode as mentioned before.

  2. Lance | Tech Support Engineer, Sr.
    Admin
    Lance | Tech Support Engineer, Sr. avatar
    414 posts

    Posted 21 Jun Link to this post

    Hi Namyslaw,

    I'm not able to replicate what you're seeing. I have built you a sample app and offer some suggestions below. 

    Take a look at my attached example, by using ListViewLoadOnDemandCollection instead of ObservableCollection<T>, the RadListView will automatically calls the action when new items are needed and you do not need to use code behind / event handler!

    ViewModel

    private int bookCount;
     
    public StartPageViewModel()
    {
        BookSource = new ListViewLoadOnDemandCollection(LoadMoreBooks);
     
        // Load some initial data
        for (var i = 0; i < 30; i++)
        {
            bookCount++;
            BookSource.Add($"Book {bookCount}");
        }
    }
     
    /// <summary>
    /// Data source for the RadListView
    /// </summary>
    public ListViewLoadOnDemandCollection BookSource { get; set; }
     
    /// <summary>
    /// Method to load more items, triggered by the RadListView via the ListViewLoadOnDemandCollection
    /// </summary>
     /// <param name="cancellationToken"></param>
    /// <returns>list of strings containing book names</returns>
    private IEnumerable<object> LoadMoreBooks(CancellationToken cancellationToken)
    {
        var result = new List<string>();
     
        try
        {
                    // Simulate 3 second connection latency
            Task.Delay(3000, cancellationToken).Wait(cancellationToken);
                     
            for (var i = 0; i < 20; i++)
            {
                bookCount++;
                result.Add($"Book {bookCount}");
            }
     
            return result;
        }
        catch (Exception ex)
        {
            return null;
        }
    }

    XAML

    <Grid>
        <Grid.BindingContext>
            <viewModels:StartPageViewModel x:Name="ViewModel" />
        </Grid.BindingContext>
        <telerikDataControls:RadListView ItemsSource="{Binding BookSource}"
                               IsLoadOnDemandEnabled="True"
                               LoadOnDemandMode="Automatic"/>
    </Grid>


    If this doesn't help, please update my attached example so that it replicates what you're seeing and send it to us for further investigation.


    Note:  Since this is a public forum thread, you cannot attach projects. Instead I recommend opening a Support Ticket here (you have a support license with your trial and can attach your repro app). Support tickets carry a guaranteed response from the UI for Xamarin support team.

    Regards,
    Lance | Tech Support Engineer, Sr.
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Shawn
    Shawn avatar
    2 posts
    Member since:
    Feb 2012

    Posted 27 Sep Link to this post

    I am not sure about all the details on how load on demand works.  My main issue with the example provided in the Getting Started guides is that:

    1. it loads infinite amount of data. In other words, it doesn't show how to end the load on demand when you have finished loading everything.  Do you set IsLoadOnDemandEnabled = false?  Do you set LoadOnDemandBufferItemsCount = 0?

    2: What is the difference between IsLoadOnDemandEnabled and IsLoadOnDemandActive?

    3. What does LoadOnDemandBufferItemsCount actually do?  It says, "number of minimum items loaded ahead" which doesn't seem correct since how would the listview be able to load something ahead without calling the LoadOnDemand event?

  4. Lance | Tech Support Engineer, Sr.
    Admin
    Lance | Tech Support Engineer, Sr. avatar
    414 posts

    Posted 27 Sep Link to this post

    Hi Shawn,

    I've replied in more depth to your support ticket on this subject, but to share the high level answers with the rest of the community.

    1 - IsLoadOnDemandEnabled

    When this is true, the RadListView will continue to run the event handler, or the ListViewLoadOnDemandCollection's Action, to fetch the next set of items. To turn it off, set IsLoadOnDemandEnabled to false.


    2 - IsLoadOnDemandActive

    This is toggled to true by the RadListView when it's currently fetching items, and false when it isn't.


    3 - The LoadOnDemandBufferItemsCount sets when to make the next call for more items.

    For example, let's say you set the buffer to 20. When user scrolls down, the RadListView will fire another fetch for items when it reaches the 20th item from the bottom of the list.


    If you have any implementation problems, or have additional questions, please reply to the Support Ticket and we'll be happy to assist further.

    Regards,
    Lance | Tech Support Engineer, Sr.
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top