I need help with Activityindicator in Xamarin.Forms

Asked

Viewed 86 times

-2

I have an application that works together with a server, where it needs to fetch some data.

When I do this search, it usually takes a certain time and I would like to put a ActivityIndicator while loading takes place.

I did it this way:

<ActivityIndicator x:Name="ActivityLoad" IsRunning="False" IsVisible="False"/>

And in the code, I made sure that when he clicked the login button, he left the ActivityIndicator visible. However, during the request to the server the application simply hangs, freezes everything, until the server returns a response. Causing the ActivityIndicator only appears on the screen when already clicked. This happens in all routines I have. (I tried to use the Async and the Await but it didn’t work)

I’ve searched a lot of places and I still can’t solve it.

2 answers

0

I believe that solves your problem

In XAML

<ActivityIndicator x:Name="ActivityLoad" IsRunning="True" Opacity="0"/>

No . Cs (c# back)

public async void ClickMethod(object sender,EventArgs e)
{
   //fazer aparecer
   await ActivityLoad.FadeTo(1,300);


   //aqui você coloca o metodo de busca

   //fazer sumir
   await ActivityLoad.FadeTo(0,300);

}
  • Unfortunately it didn’t work. I kept looking and used Rg.Popup, a nuget in the project. This way, I created a transparent popup with Activity Indicator running. Every time I need to load, I call the popup to the screen, then close. It got a little tricky but it’s the only way I found of not locking everything during the request on the server.

-1

Is the call to your server asynchronous? If it is not asynchronous it will probably freeze even, try to leave the call to the asynchronous server.

Before calling the method that makes the request put the ActivityIndicator for

IsRunning = True 
IsVisible = True

And when he finishes the request put below the method

IsRunning = false
IsVisible = false

Browser other questions tagged

You are not signed in. Login or sign up in order to post.