Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

listview ispulltorefreshenabled not spinning

ganesh96ganesh96 Member ✭✭✭

I'm using ispulltorefreshenabled to refresh a list. The list gets refreshed and stops when it finishes (by setting IsRefreshing = false), so everything works fine.
Thing is: when the list is refreshing, the loading spinner is not spinning. It just gets 'stuck' during this process.

How to get the refreshing spinner keep spinning while the list is refreshed?

Tagged:

Best Answer

Answers

  • JarvanJarvan Member, Xamarin Team Xamurai

    when the list is refreshing, the loading spinner is not spinning. It just gets 'stuck' during this process.

    How did you achieve the refresh function? Try to set binding to the RefreshCommand and wait the data to be loaded.

    Check the code:
    Page.xaml

    <ListView x:Name="listView" ItemsSource="{Binding models}" IsPullToRefreshEnabled="True" RefreshCommand="{Binding command}">
        ...
    </ListView>
    

    Page.xaml.cs

    public partial class Page3 : ContentPage
    {
        public ICommand command { get; set; }
        public ObservableCollection<_Model> models { get; set; }
        public Page3()
        {
            InitializeComponent();
    
            models = new ObservableCollection<_Model>();
            //add data
    
            command = new Command(method);
    
            BindingContext = this;
        }
    
        private async void method(object obj)
        {
            await Task.Delay(2000);//loading the data
    
            listView.IsRefreshing = false;
        }
    }
    

  • ganesh96ganesh96 Member ✭✭✭

    Using await Task.Delay() works, but the spinner is now spinning for 2 seconds before freezing. Sometimes loading takes one 1 second, sometimes it takes 5 seconds.

    How to manage that?

  • JarvanJarvan Member, Xamarin Team Xamurai
    edited August 28

    Using await Task.Delay() works, but the spinner is now spinning for 2 seconds before freezing. Sometimes loading takes one 1 second, sometimes it takes 5 seconds.

    Add the loading data code before listView.IsRefreshing = false;.

    private async void method(object obj)
    {
        //update the data
    
        listView.IsRefreshing = false;
    }
    
  • ganesh96ganesh96 Member ✭✭✭

    I have a method that gives the list an update, how to insert that in you code?

  • JarvanJarvan Member, Xamarin Team Xamurai

    I posted a basic demo you coul refer to the code.

  • ganesh96ganesh96 Member ✭✭✭

    It's also not spinning in your example.

  • JarvanJarvan Member, Xamarin Team Xamurai

    It works but only spins a very little time because loading data doesn't require much time.

    If you want the spinning to be obvious, you could add a delay to make that.

    private async void method(object obj)
    {
        models.Add(new CustomModel { ... });
        ...
    
        await Task.Delay(500);
    
        listView.IsRefreshing = false;
    }
    
  • ganesh96ganesh96 Member ✭✭✭

    I also implemented your demo code in my code (where it takes a few seconds to load) and it still gets stuck.

  • JarvanJarvan Member, Xamarin Team Xamurai

    Could you share a basic demo to reproduce the issue?

  • ganesh96ganesh96 Member ✭✭✭

    No not possible. Now I'm using Acr.UserDialogs to show loading when refreshing. I created a method and when a button is clicked or OnAppearing(), this method is refreshing the list. No I want to change that by a Pull-To-Refresh gesture. This works, but the loading spinner is simply not spinning.

  • JarvanJarvan Member, Xamarin Team Xamurai
    edited August 31

    This works, but the loading spinner is simply not spinning.

    Do you mean the data is updated when pulling to refresh? But the spinner doesn't spin?

    No I want to change that by a Pull-To-Refresh gesture.

    Did you use the spinner and the UserDialogs both? I test the code with the plugin, it also works well.

  • ganesh96ganesh96 Member ✭✭✭

    Do you mean the data is updated when pulling to refresh? But the spinner doesn't spin?

    Indeed. The list does update, but the spinner doesn't spin.

    Did you use the spinner and the UserDialogs both? I test the code with the plugin, it also works well.

    I use UserDialogs for other things, but not for this. I really want to have the spinner.

  • JarvanJarvan Member, Xamarin Team Xamurai

    Please post the related code or share a bais demo to reproduce the issue, it'll help to get a solution.

  • ganesh96ganesh96 Member ✭✭✭

    Hi @YelinZh

    I used the demo given earlier to create a demo where you can see my issue. 5000 new items are added each time you refresh the list. In the real app I don't have that much lines, but the problem here is visible: the spinner is not spinning.

    Tested on physical Samsung Galaxy S10.

  • ganesh96ganesh96 Member ✭✭✭

    I understand the solution, its just very difficult to implement this in my code. So I have to think about that one.

Sign In or Register to comment.